安装mysql

  • 1.下载mysql源安装包
        shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
  • 2.安装mysql源
        shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm 
  • 3.检查mysql源是否安装成功
shell> yum repolist enabled | grep "mysql.*-community.*"
  • 4.修改 vim /etc/yum.repos.d/mysql-community.repo源 ,改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。
vim /etc/yum.repos.d/mysql-community.repo
  • 5.安装MySQL
shell> yum install mysql-community-server
  • 6.启动MySQL服务
shell> systemctl start mysqld
  • 7.开机启动
shell> systemctl enable mysqld
shell> systemctl daemon-reload
  • 8.修改root本地登录密码

1)查看mysql密码

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

2)连接mysql

shell> mysql -uroot -p

3)修改密码[注意:后面的分号一定要跟上]

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

或者:

mysql> set password for 'root'@'localhost'=password('MyNewPass4!'); 

mysql> show variables like '%password%';

  • 9.添加远程登录用户
mysql> GRANT ALL PRIVILEGES ON *.* TO 'caoxiaobo'@'%' IDENTIFIED BY 'Caoxiaobo0917!' WITH GRANT OPTION;
  • 10.设置密码安全规则
   set global validate_password_policy=0;
   set global validate_password_length=1;
  • 11.刷新映射关系
flush privileges;

卸载mysql

yum方式安装的mysql
1、yum remove mysql mysql-server mysql-libs compat-mysql51

2、rm -rf /var/lib/mysql

3、rm /etc/my.cnf

查看是否还有mysql软件:

rpm -qa|grep mysql

如果存在的话,继续删除即可。

rpm方式安装的mysql

a)查看系统中是否以rpm包安装的mysql:

[root@localhost opt]# rpm -qa | grep -i mysql
MySQL-server-5.6.17-1.el6.i686
MySQL-client-5.6.17-1.el6.i686

b)卸载mysql

[root@localhost local]# rpm -e MySQL-server-5.6.17-1.el6.i686
[root@localhost local]# rpm -e MySQL-client-5.6.17-1.el6.i686

c)删除mysql服务

[root@localhost local]# chkconfig --list | grep -i mysql
[root@localhost local]# chkconfig --del mysql

d)删除分散mysql文件夹

[root@localhost local]# whereis mysql 或者 find / -name mysql

mysql: /usr/lib/mysql /usr/share/mysql
清空相关mysql的所有目录以及文件
rm -rf /usr/lib/mysql
rm -rf /usr/share/mysql
rm -rf /usr/my.cnf

【本文参考地址】(https://www.cnblogs.com/caoxb...
【参考2】(https://www.cnblogs.com/wangh...


西安小哥
1.3k 声望88 粉丝

thinking、doing、do better、do much better than today。exchange 、sharing、improve as quickly as possible。