CentOS7.5 安装MySql教程

时间:2021-03-07 07:27:01

CentOS7位安装MySql教程

1.先检查系统是否装有mysql

rpm -qa | grep mysql

2.下载mysql的repo源

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

如果报错: -bash: wget: 未找到命令

安装插件  yum -y install wget

3.安装 mysql-community-release-el7-5.noarch.rpm包

sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

4.安装MySQL

sudo yum install mysql-server

5.重置MySQL密码

mysql -u root

如果报错:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

原因:原因是/var/lib/mysql的访问权限问题。

chown root /var/lib/mysql/

重启MySQL服务

service mysqld restart

接着登陆设置密码

mysql -u root

use mysql;

update user set password=password('123456') where user='root';

exit;

6.重启MySQL服务

service mysqld restart

接着设置Root账户远程连接密码,账户和密码都是 root

mysql -u root -p

GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; 

重启服务器

service mysqld restart

7.使用外网工具连接MySQL

连接mysql的用户名和密码都是 root

关闭防火墙

systemctl stop firewalld.service