CentOS 7下卸载旧版MySQL 重装新的mysql

先介绍卸载

  • yum方式

    查看yum是否安装过mysql
    yum list installed mysql*
    
    • 1
    • 2
    • 3

如或显示了列表,说明系统中有MySQL 

  • yum卸载 
    根据列表上的名字

    yum remove mysql-community-client mysql-community-common mysql-community-libs mysql-community-libs-compat mysql-community-server mysql57-community-release
    rm -rf /var/lib/mysql  
    rm /etc/my.cnf
    
    • 1
    • 2
    • 3
    • 4
  • rpm查看安装

    rpm -qa | grep -i mysql
    
    • 1
    • 2

  • rpm 卸载

    rpm -e mysql57-community-release-el7-9.noarch
    rpm -e mysql-community-server-5.7.17-1.el7.x86_64
    rpm -e mysql-community-libs-5.7.17-1.el7.x86_64
    rpm -e mysql-community-libs-compat-5.7.17-1.el7.x86_64
    rpm -e mysql-community-common-5.7.17-1.el7.x86_64
    rpm -e mysql-community-client-5.7.17-1.el7.x86_64
    cd /var/lib/  
    rm -rf mysql/
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
  • 清除余项

    whereis mysql
    mysql: /usr/bin/mysql /usr/lib64/mysql /usr/local/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
    #删除上面的文件夹
    rm -rf /usr/bin/mysql
    
    • 1
    • 2
    • 3
    • 4
    • 5

    … 
    … 
    我就省略了

  • 删除配置

    rm –rf /usr/my.cnf
    rm -rf /root/.mysql_sercret
    
    • 1
    • 2
    • 3

剩余配置检查

chkconfig --list | grep -i mysql
chkconfig --del mysqld
  • 1
  • 2
  • 3

根据上面的列表,删除 ,如:mysqld

再介绍安装


按照官方的文档进行安装 
http://dev.mysql.com/doc/refman/5.7/en/installing.html 

http://dev.mysql.com/doc/refman/5.7/en/linux-installation.html


文档地址:http://dev.mysql.com/doc/refman/5.7/en/linux-installation.html

3是各种安装方式列表 
CentOS用yum安装相对省事,省去很多配置环节

yum安装,先要搞到源

wget http://repo.mysql.com/mysql57-community-release-el7-9.noarch.rpm
sudo rpm -ivh mysql57-community-release-el7-9.noarch.rpm
  • 1
  • 2
  • 3

接下来使用yum安装

更新yum软件包

yum check-update  
  • 1
  • 2

更新系统

yum update
  • 1
  • 2

安装mysql

yum install mysql mysql-server
  • 1
  • 2

接下来是漫长的等待。如果中途关机,或者下载挂了,请执行卸载步骤后,再来一次。

完成后

记住要给root上密码

/usr/local/mysql/bin/mysqld_safe --skip-grant-tables --user=mysql &
systemctl start mysqld
mysql -u root

mysql> update mysql.user set authentication_string=password('new_password') where user='root' and Host ='localhost';
mysql> flush privileges;
mysql> quit;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

启动与开放远程访问

systemctl start mysqld
mysql -u root -p
+ 授权远程访问
use mysql;
grant all privileges  on *.* to root@'%' identified by "root";
FLUSH RIVILEGES;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

建议root不要授权远程访问,请创建新mysql用户


mysql> show databases;

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

解决如下:

1: SET PASSWORD = PASSWORD('123456@Qpf');

2:ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;

3:flush privileges;

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

Fei joe 清华同衡thupdi

展开阅读全文

没有更多推荐了,返回首页