centos7.5安装mysql5.7

卸载mariadb

centos7.5 不支持mysql,内部集成了mariadb,而安装mysql的话会和mariadb的文件冲突,所以需要先卸载掉mariadb。

rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs

下载源

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-common-5.7.24-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-libs-5.7.24-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.24-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.24-1.el7.x86_64.rpm

安装源

mysql安装存在依赖关系,一定要顺序安装。

rpm -ivh mysql-community-common-5.7.24-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.24-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.24-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.24-1.el7.x86_64.rpm

检验是否安装成功

mysql --version

mysql服务常用命令

# 查看mysql服务状态
systemctl status mysqld.service
# 启动mysql服务
systemctl start mysqld.service
# 关闭mysql服务
systemctl stop mysqld.service
# 重启mysql服务
systemctl restart mysqld.service
# 设置mysql开机启动
systemctl enable mysqld.service
# 禁止mysql开机启动
systemctl disable mysqld.service

重置mysql密码

mysql的默认配置
配置文件:/etc/my.cnf
日志文件:var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
不重制密码是不可以进行任何操作的,而且mysql有个密码策略,一定要符合要求,不然会提示错误:
You must reset your password using ALTER USER statement before executing this statement.
mysql初始密码在mysqld.log 中。

# 启动mysql
[root@instance-d2zfyywa ~]# systemctl start mysqld.service 
# 获取初始密码
[root@instance-d2zfyywa ~]# grep "password" /var/log/mysqld.log 
2019-01-15T06:36:05.918050Z 1 [Note] A temporary password is generated for root@localhost: .aL=ur_95qj<
# 登录
[root@instance-d2zfyywa ~]# mysql -uroot -p                                                                                        
Enter password: 
# 修改密码
mysql> alter user 'root'@'localhost' identified by 'Root123!';                                                                     
Query OK, 0 rows affected (0.00 sec)
# 刷新权限
mysql> flush privileges;                                                                                                           
Query OK, 0 rows affected (0.00 sec)

创建外连用户并授予权限

创建数据库test;
创建外连用户user1,并赋予test库所有权限。

mysql> create database test;
mysql> create user 'user1'@'%' identified by 'User123!';
mysql> grant all privileges on test.* to 'user1'@'%' identified by 'User123!';
mysql> flush privileges; 

你可能感兴趣的:(linux)