Centos6.4 MySQL安装与配置

安装命令:

yum install mysql #安装客户端

yum install mysql-server #安装服务器

yum install mysql-devel #安装开发库

安装完成后,修改密码:

/etc/init.d/mysqld stop  
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &  
mysql -u root mysql   
mysql> UPDATE user SET Password=PASSWORD('root') where USER='root';   
mysql> FLUSH PRIVILEGES;   
mysql> quit  
/etc/init.d/mysql restart  

mysql -uroot -p Enter password: <输入新密码123456> mysql>

  

修改配置文件使其采用UTF-8编码:

vi /etc/my.cnf

#mysqld下添加
[mysqld]
default-character-set=utf8

#新建client节点
[client]
default-character-set=utf8

开启远程数据库连接:

先将数据库绑定到本地默认IP:0.0.0.0

修改/etc/my.cnf,在mysqld下添加一行

[mysqld]

bind-address = 0.0.0.0

进入mysql,修改权限:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

mysql> FLUSH PRIVILEGES;   

 其中前面一个root是远程连接的用户名,后面一个root就是远程连接的密码。

新建用户,并赋予某个数据库的权限给新用户:

添加一个用户名为shared,密码为shared的用户,

将数据库shard的所有权限赋予给所有主机(包括远程连接)上的shared用户

1 insert into mysql.user(Host,User,Password) values('localhost','shared',password('shared')); 
2 grant all privileges on shared.* to shared@'%' identified by 'shared'; 
3 flush privileges;

重启mysql服务:

service mysqld restart
原文地址:https://www.cnblogs.com/itZhy/p/3258722.html