1. 下载server和client rpm包
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-server-5.6.35-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-client-5.6.35-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-5.6.35-1.el7.x86_64.rpm-bundle.tar
2. 本地安装
yum localinstall MySQL-server-5.6.35-1.el7.x86_64.rpm
yum localinstall MySQL-client-5.6.35-1.el7.x86_64.rpm
3. 运行mysql_install_db
mysql_install_db --user=mysql
4. 如果在第三步出错
FATAL ERROR: please install the following Perl modules before executing /usr/bin/mysql_install_db: Data::Dumper
则yum -y install autoconf来解决。然后再执行上一步。
5. 这时已经可以,测试一下启动mysql
cd /usr ; /usr/bin/mysqld_safe &
6. 然后通过mysql client来登录进去check一下
mysql -u root -p
这时没有密码.(我这是mysql 5.6.35;之前的版本好像是有个随机的初始密码存放在/root/.mysql_secret)
7. 考虑安全性,需要运行
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h VM_55_254_centos password 'new-password'
或者直接运行
mysql_secure_installation
这里将设置root密码,删除匿名账户,删除test数据库等
8. 在第7步中可能会出现找不到/var/lib/mysql/mysql.sock的情况,那就需要建立软连接。
ln -s /home/test/mysql/mysql.socket /var/lib/mysql/mysql.sock
其中/home/test/mysql/mysql.socket为当前使用的socket
9. 创建新用户并设置权限
create user newusercount@‘localhost’ identified by ‘12345’;
grant select, update on test.* to newusercount@‘localhost’;