准备
1.查看Linux中是否安装了Mysql或者Maridb,若安装会有输出
rpm -qa|grep mysql
rpm -qa|grep mariadb
2.卸载mysql或者maridb
rpm -e --nodeps mysql-libs-5.1.73-7.el6.x86_64
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
MySQL压缩包
1.下载
2.上传
3.解压
- tar -xvf mysql-5.7.36-1.el7.x86_64.rpm-bundle.tar
4.解压后得到以下的rpm包,依次安装所需要的rpm包
- rpm -ivh mysql-community-common-5.7.36-1.el7.x86_64.rpm
- rpm -ivh mysql-community-libs-5.7.36-1.el7.x86_64.rpm
- rpm -ivh mysql-community-libs-compat-5.7.36-1.el7.x86_64.rpm
- rpm -ivh mysql-community-client-5.7.36-1.el7.x86_64.rpm
- rpm -ivh mysql-community-server-5.7.36-1.el7.x86_64.rpm
- 如果出现报错,则在上面命令最后加上 --force --nodeps
5.查看安装情况
- rpm -qa | grep mysql
启动mysql服务
- systemctl start mysqld.service
- 如果启动报错,可以执行journalctl -xe指令查看错误信息
- 这里给出一种报错
- 解决
查看是否安装了libaio
rpm -qa | grep libaio
没有输出则安装
yum install -y libaio
再次启动
systemctl start mysqld.service
设置新密码
1.查看初始密码(要记住这个密码之后会用到)
- cat /var/log/mysqld.log | grep password
2.用初始化的密码登录mysql
- mysql -uroot -p
3.重置密码
- SHOW variables LIKE ‘validate_password%’;
- 报错
- exit退出mysql控制台
- vim /etc/my.cnf
#添加密码验证插件
plugin-load-add=validate_password.so
#服务器在启动时加载插件,并防止在服务器运行时删除插件
validate-password=FORCE_PLUS_PERMANENT
systemctl restart mysqld
mysql -uroot -p
set global validate_password_policy=0;
set global validate_password_length=1;
- 设置新密码
alter user 'root'@'localhost' identified by 'aaaa';
- 设置完成后重新进入mysql服务器,输入新的密码进行登录
exit
mysql -uroot -p
开放mysql数据库的端口,允许远程连接
1.查看防火墙是否关闭,若未关闭则关闭
- systemctl status firewalld.service
- 暂时关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
2.设置mysql远程连接权限
- mysql -uroot -p
- show databases;
- use mysql;
- select user,host from user;
- update user set host = ‘%’ where user = ‘root’;
%为任意访问地址
刷新权限 权限更新后刷新才会起作用
设置mysql中文编码
1. 编辑配置文件
- vim /etc/my.cnf
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
2.重启mysql服务
设置mysql开机启动
1.修改rc.local
- vim /etc/rc.local
service mysqld start