centos6.5安装MySQL5.7及配置

时间:2021-06-23 21:06:49

0、下载对应的MySQL的RPM文件

https://dev.mysql.com/downloads/mysql/

1、查看CentOS自带MySQL 5.1组件并卸载。

rpm -qa | grep -i mysql  
rpm -e --nodeps mysql-libs-5.1.61-4.el6.x86_64

2、  安装依赖(MySQL 5.5并不需要这个依赖,但是5.7必须要,否则server组件无法安装成功)

yum -y install numactl 
3、  安装MySQL(下面的安装顺序不能错,否则会安装失败)

        rpm -ivh mysql-community-common-5.7.10-1.el6.x86_64.rpm  
	rpm -ivh mysql-community-libs-5.7.10-1.el6.x86_64.rpm  
	rpm -ivh mysql-community-client-5.7.10-1.el6.x86_64.rpm  
	rpm -ivh mysql-community-server-5.7.10-1.el6.x86_64.rpm 

4、修改数据库编码,在文件/etc/my.cnf中添加如下

        [client]  
	default-character-set=utf8mb4  
	[mysqld]  
	character_set_server=utf8mb4 

5、启动MySQL(下面的命令请执行两次。非常奇怪,不知为什么第一次一定失败,第二次却一定成功)

        service mysqld start  

6、获得MySQL初始密码

	grep 'temporary password' /var/log/mysqld.log  

7、使用上一步获得的密码登录MySQL,并修改初始密码
        mysql -uroot -p'初始密码'  
	ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; 

此时数据库工具并不能访问数据库,解决如下
8、给本地IP付所有权限并重启数据库
        mysql> grant all privileges on *.* to root@"%" identified by "563412";
	mysql> flush privileges;
	# service mysqld restart

9、关闭防火墙

# service  iptables stop