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. 修改数据库编码。
为了保证数据库能正确处理中文,我们需要设定数据库默认的编码为utf8。修改/etc/my.cnf文件,并在其中加入以下
default-character-set=utf8mb4
character_set_server=utf8mb4
(如果启动失败改为character_set_server=utf8可以启动成功)
5. 启动MySQL(下面的命令请执行两次。非常奇怪,不知为什么第一次一定失败,第二次却一定成功)
service mysqld start
(启动失败按 http://www.cnblogs.com/kerrycode/p/4364465.html卸载重装)
6. 获得MySQL初始密码
grep 'temporary password' /var/log/mysqld.log
7. 使用上一步获得的密码登录MySQL,并修改初始密码
mysql -uroot -p'初始密码'
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
8.切换用户:
mysql -u root -p
远程授权;
GRANT ALL PRIVILEGES ON . TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;
9.关闭防火墙
service iptables status
service iptables stop
mysql安全启动
mysqld_safe -defaults-file=/etc/my.cnf -user=mysql &