el7系列
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
el6系列
wget https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
rpm -ivh mysql57-community-release-el6-11.noarch.rpm
切换repo的5.5/5.6/5.7版本
sudo yum-config-manager --disable mysql57-community
sudo yum-config-manager --enable mysql56-community
刷新repo
yum makecache
启动服务
sudo service mysqld start
sudo systemctl start mysqld.service
查看服务
sudo service mysqld status
sudo systemctl status mysqld.service
5.7版本修改初始密码
sudo grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
5.6版本修改初始密码(因为在安装过程中设置了)
mysql_secure_installation
修改最大连接数
1.修改系统文件打开限制/etc/security/limits.conf
mysql hard nofile 65535
mysql soft nofile 65535
2.修改my.cnf
在[mysqld_safe]部分加入
max_connections=5000
3.修改/lib/systemd/system/mysqld.service
在[Service]部分加入
LimitCORE=infinity
LimitNOFILE=100001
LimitNPROC=100001
4.重载
systemctl daemon-reload
systemctl restart mysqld.service
开启MySQL远程访问权限 允许远程连接
1、登录服务器,然后运行命令:mysql -u root –p ,然后输入密码,该步骤是进入数据库。
2、mysql>use mysql;
3、授权:
例如想root使用123456从任何主机连接到mysql服务器:
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
如果想允许用户abc从ip为10.10.50.127的主机连接到mysql服务器,并使用654321作为密码:
mysql>GRANT ALL PRIVILEGES ON *.* TO 'abc'@'10.10.50.127' IDENTIFIED BY '654321' WITH GRANT OPTION;
4、刷新权限:
mysql>FLUSH PRIVILEGES;
PS:忘记密码怎么办
1.首先停止mysql服务器
service mysql stop
2.使用--skip-grant-tables选项跳过授权表验证,
--skip-grant-tables Start without grant tables. This gives all users FULL
ACCESS to all tables.
使用--skip-grant-tables启动mysql服务器
mysqld --skip-grant-tables --user=mysql
查看启动情况
ps -ef | grep mysql
mysql 10209 14240 4 13:52 pts/0 00:00:00 mysqld --skip-grant-tables --user=mysql
root 10229 14240 0 13:53 pts/0 00:00:00 grep mysql
3.我们切换到mysql数据库下尝试
root@localhost[(none)]> use mysql
4.尝试用password函数方式来更新password列
root@localhost[mysql]> update user set password=password('passwd') where user='root'; --此方式更新成功
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
5.验证
root@localhost[mysql]> select host,user,password from user where user='root'; --可以看到密码已经变成了密文
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| localhost | root | *59C70DA2F3E3A5BDF46B68F5C8B8F25762BCCEF0 |
+-----------+------+-------------------------------------------+
6.刷新权限
root@localhost[mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
7.最好重启mysql
网友评论