Centos安装和配置Mysql5.7

时间:2022-05-03 01:47:12

步:下载和安装mysql源

 

先下载 mysql源安装包

[[email protected] ~]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

-bash: wget: 未找到命令

我们先安装下wget 

yum -y install wget

然后执行 

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

安装mysql源

yum -y localinstall mysql57-community-release-el7-11.noarch.rpm 

 

 

步:在线安装Mysql

yum -y install mysql-community-server

下载的东西比较多 要稍微等会;

 

步:启动Mysql服务

systemctl start mysqld

设置开机启动

 

[[email protected] ~]# systemctl enable mysqld
[[email protected] ~]# systemctl daemon-reload

 

 

 

步:修改root本地登录密码

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个临时的默认密码。

[[email protected] ~]# vi /var/log/mysqld.log

 

Centos安装和配置Mysql5.7

[[email protected] ~]#  mysql -u root -p
Enter password: 

 

输入临时密码 进入mysql命令行;

ALTER USER root@localhost IDENTIFIED BY root;// 若报错

set global validate_password_policy=0;

set global validate_password_length=4;

ALTER USER root@localhost IDENTIFIED BY root’;

步:设置允许远程登录

Mysql默认不允许远程登录,我们需要设置下,并且防火墙开放3306端口;

mysql> GRANT ALL PRIVILEGES ON *.* TO root@% IDENTIFIED BY root WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> exit;
Bye

退出下;

[[email protected] ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[[email protected] ~]# firewall-cmd --reload
success

 

步:配置默认编码为utf8

[[email protected] ~]# vi /etc/my.cnf

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

[mysqld]

character_set_server=utf8

init_connect=SET NAMES utf8

自此已无大碍!