Linux环境MySQL的安装及配置

1. 安装MySQL-Server(yum)

[root@localhost ~]# yum list | grep mysql
[root@localhost ~]# yum install mysql-server.x86_64 

2. 配置:

    表名不区分大小写配置

    打开文件

[root@localhost ~]# vi /etc/my.cnf

    修改

[mysqld]
lower_case_table_names=1

   重启

[root@localhost ~]# service mysqld restart 
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

3. 启动数据库

[root@localhost ~]# service mysqld start
[root@localhost ~]# service mysqld start 
Initializing MySQL database:  Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

4.修改root用户密码

[root@localhost ~]# mysqladmin -u root password 'new-password'
[root@localhost ~]# mysqladmin -u root -h localhost.localdomain password 'new-password' -p

5.登陆数据库

[root@localhost etc]# mysql -u root -p
mysql> use mysql;
mysql> select host,user,password from user;
+-----------------------+------+-------------------------------------------+
| host                  | user | password                                  |
+-----------------------+------+-------------------------------------------+
| localhost             | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| localhost.localdomain | root |                                           |
| 127.0.0.1             | root |                                           |
| localhost             |      |                                           |
| localhost.localdomain |      |                                           |
+-----------------------+------+-------------------------------------------+
5 rows in set (0.00 sec)

6. 创建数据库

CREATE DATABASE `YourDBName`CHARACTER SET utf8 ;

7. 创建用户

INSERT INTO USER(HOST,USER,PASSWORD) VALUES('%','YourDBUsername',PASSWORD('YourDBPassword'));  
FLUSH PRIVILEGES;

 8. 用户授权(查询,更新,修改,删除...)

GRANT ALL ON YourDBName.* TO YourDBUsername@'%';
FLUSH PRIVILEGES; 

9. 安全考虑(局域网访问, 3306端口, 防火墙设置, 外网只能使用限制用户访问)

猜你喜欢

转载自feticoolo.iteye.com/blog/1974107