1.准备工作
下载解压:MySQL-5.6.30-1.el6.x86_64.rpm-bundle.tar 套件
tar -xf [MySQL-5.6.30-1.el6.x86_64.rpm-bundle.tar
套件中包含有:
-rw-r--r-- 1 7155 31415 3424912 Mar 4 17:14 MySQL-devel-5.6.30-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 89732912 Mar 4 17:14 MySQL-embedded-5.6.30-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 56982836 Mar 4 17:15 MySQL-server-5.6.30-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 1961716 Mar 4 17:15 MySQL-shared-5.6.30-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 3969756 Mar 4 17:15 MySQL-shared-compat-5.6.30-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 51401352 Mar 4 17:15 MySQL-test-5.6.30-1.el6.x86_64.rpm
其中server、client、devel、shared、shared-compat是必须安装的,否则后面安装MySQL-Python包的时候会出现错误。
2. 卸载MySQL
备份数据库,db1和db2就是需要备份的数据库:
mysqldump -uroot -p --databases db1 db2 > dumps.sql
停止MySQL服务:
service mysqld stop
或者
/etc/init.d/mysql stop
既然是重新安装MySQL,那么就要把先前的文件全部清理干净。首先检查已经安装的MySQL包:
$ rpm -qa |grep -i mysql
MySQL-server-5.6.30-1.el6.x86_64
MySQL-devel-5.6.30-1.el6.x86_64
MySQL-python-1.2.3-0.3.c1.1.el6.x86_64
MySQL-client-5.6.30-1.el6.x86_64
MySQL-shared-compat-5.6.30-1.el6.x86_64
卸载MySQL安装包
rpm -ev mysql-community-server-5.6.24-3.el6.x86_64
rpm -ev mysql-community-client-5.6.24-3.el6.x86_64
# 下面这些删除时需要依赖其他文件,通过指定参数强制删除
rpm -ev --nodeps mysql-community-libs-compat-5.6.24-3.el6.x86_64
rpm -ev --nodeps mysql-community-libs-5.6.24-3.el6.x86_64
rpm -ev --nodeps mysql-community-common-5.6.24-3.el6.x86_64
删除MySQL相关目录
$ find / -iname mysql
/var/lib/mysql
/usr/share/mysql
$ rm -rf /var/lib/mysql
$ rm -rf /usr/share/mysql
3.安装MySQL
$ rpm -ivh MySQL-server-5.6.30-1.el6.x86_64.rpm
$ rpm -ivh MySQL-client-5.6.30-1.el6.x86_64.rpm
$ rpm -ivh MySQL-devel-5.6.30-1.el6.x86_64.rpm
$ rpm -ivh MySQL-shared-5.6.30-1.el6.x86_64.rpm
$ rpm -ivh MySQL-shared-compat-5.6.30-1.el6.x86_64.rpm
安装完成后,MySQL会创建一个临时root密码在/root/.mysql_secret
文件中,第一次启动的时候需要用该密码登录,登录成功后,必须修改密码才能进行其他操作。
$ service mysql start
修改密码
SET PASSWORD = PASSWORD('xxxxxxxx');
或者
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
4.开启远程连接
mysql> use mysql;
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";
mysql> flush privileges;
mysql> exit
5.数据恢复
mysql -uroot -pxxxxx < ~/dumps.sql
yum 安装方法
sudo yum update
rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/mysql-community.repo
yum --enablerepo=mysql80-community install mysql-community-server # 这一步可能报错的话,执行下一条
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
yum --enablerepo=mysql80-community install mysql-community-server
启动mysql
sudo systemctl start mysqld # 启动
sudo systemctl status mysqld # 查看运行状态
sudo systemctl enable mysqld # 开机自启动
初始密码
sudo grep 'temporary password' /var/log/mysqld.log # 显式初始密码
关注公众号「Python之禅」,回复「1024」免费获取Python资源