CentOS7卸载并安装mysql教程

MySQL安装

先卸载其他

删除Mysql

yum remove  mysql mysql-server mysql-libs mysql-server;

find / -name mysql 将找到的相关东西delete掉(rm -rf /var/lib/mysql);

rpm -qa|grep mysql(查询出来的东东yum remove掉)
rm /etc/my.cnf

查看是否还有mysql软件:
rpm -qa|grep 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

f)清空相关mysql的所有目录以及文件

rm -rf /usr/lib/mysql
rm -rf /usr/share/mysql
rm -rf /usr/my.cnf

注意要停止mysql服务(ps -ef | grep mysql)

安装MySQL

cd /usr/local/src/
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm 
rpm -ivh mysql57-community-release-el7-8.noarch.rpm 
yum -y install mysql-server 

  • 如果有问题
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server
service mysqld restart

启动服务

启动 MySQL:

systemctl start mysqld

查看 MySQL 运行状态:

systemctl status mysqld

查看密码并修改密码

登陆mysql更改初始密码
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement
修改密码即可

grep 'temporary password'  /var/log/mysqld.log 
set password=password(“密码”);

允许用户远程连接mysql

grant all privileges on *.* to root@'%'identified by 'password';
FLUSH   PRIVILEGES;

你可能感兴趣的:(数据库)