1.通过MobaXterm工具连接Linux系统
2.查找已经安装的mysql.
rpm -qa | grep -i mysql
MySQL-server-5.6.43-1.el6.x86_64
MySQL-client-5.6.43-1.el6.x86_64
MySQL-devel-5.6.43-1.el6.x86_64 出现等信息
3.yum -y remove MySQL-server-5.6.43-1.el6.x86_64 依次删除
- find / -name mysql
查找mysql的一些目录,把所有出现的目录统统删除.可以使用rm -rf 路径,删除时请注意,一旦删除无法恢复。
5.rm -rf /etc/my.cnf
这个是删除配置文件
6.rm -rf /root/.mysql_sercret
删除mysql的默认密码,如果不删除,以后安装mysql这个sercret中的默认密码不会变,使用其中的默认密码就可能会报类似Access denied for user ‘root@localhost’ (using password:yes)的错误.
2~6步完成之后,这样mysql就全部删除干净了.
7.首先需要下载官方yum源
wget https://repo.mysql.com/mysql57-community-release-el7.rpm
8.安装yum源
yum -y install mysql57-community-release-el7.rpm
9.一切准备就绪,现在可以安装mysql服务器了
yum -y install mysql-community-server
10.修改mysql默认字符集(配置文件)
vi /etc/my.cnf
在[mysqld]下添加如下内容:
character-set-server=utf8
collation-server=utf8_general_ci
-- 在文件最下方添加
[client]
default-character-set=utf8
退出保存
11.启动mysql服务
systemctl start mysqld
12.初始化数据库的时候会为root设置一个默认密码,使用下面语句直接提取出密码
grep “password is generated” /var/log/mysqld.log | awk ‘{print $NF}’
或者执行
cat /var/log/mysqld.log
在root@localhost:后面的就是初始密码
复制一下密码
-
登录mysql
mysql -u root -p 敲回车
粘贴密码 -
修改mysql登录密码(一行一行的执行)
set global validate_password_policy=0;
set global validate_password_length=1;
set password=password(‘新密码’);
-
授予远程连接权限
//授权
在这里插入代码片
grant all privileges on *.* to 'root' @'%' identified by '自己设定的密码';
//刷新
flush privileges;
16.exit 回车
-
关闭Linux系统防火墙
systemctl stop firewalld -
重启mysql服务
service mysqld restart
19.启动数据库
mysql -u root -p
20.输入自己设置的新密码