一、配置 yum 源
1、下载mysql源安装包shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm]2、安装mysql源shell> yum -y localinstall mysql57-community-release-el7-8.noarch.rpm# 检查mysql源是否安装成功shell> yum repolist enabled | grep "mysql.*-community.*"
二、安装 mysql
1、安装 mysql servershell> yum -y install mysql-community-server2、启动shell> systemctl start mysqld3、查看状态shell> systemctl status mysqld● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 一 2016-11-14 20:11:36 +03; 1 day 14h ago Main PID: 7683 (mysqld) CGroup: /system.slice/mysqld.service └─7683 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid11月 14 20:11:35 DB-test systemd[1]: Starting MySQL Server...11月 14 20:11:36 DB-test systemd[1]: Started MySQL Server.4、停止shell> systemctl stop mysqld5、设置开机启动shell> systemctl enable mysqld6、取消开机启动shell> systemctl daemon-reload
三、修改 root 密码
1、修改密码# 安装完成之后会在/var/log/mysqld.log生成一个默认密码,通过以下命令可以查看shell> grep 'temporary password' /var/log/mysqld.log[Note] A temporary password is generated for root@localhost: j8)A4banfiks# 末尾的 j8)A4banfiks 就是root 用户的初始密码shell> mysql -uroot -pmysql> set password for 'root'@'localhost'=password('yourpassword'); # yourpassword:替换成你的密码2、修改密码安全策略# MySQL 5.7默认密码策略要求英文大小写、数字加符号,并且长度不能小于8位# 查看密码安全策略shell> show variables like 'validate_password%';# validate_password_policy 可以设为0、1(默认)、2,分别代表从低到高的密码强度,改为0则是最低的密码强度,可以随意设置密码shell> set global validate_password_policy=0;
四、添加远程访问账户
mysql> grant all privileges on *.* to 'username'@'%' identified by 'password' with grant option;# 请将 username 替换成你的账户# 请将 password 替换成你的密码
五、编辑配置文件
shell> vim /etc/my.cnf...[mysqld]# 开启远程访问。127.0.0.1 表示只允许本机访问,0.0.0.0 表示任何机器均可访问,如要指定机器访问则将 值设为指定机器的 IPbind-address = 0.0.0.0# 设置最大连接数max_connections = 1000...# 重启 msyqlshell> sytemctl restart mysqld
六、查看最大连接数
mysql> show variables like 'max_connections';