重置密码前,首先要登录
1 | mysql -u root |
登录时有可能报这样的错:ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2),原因是/var/lib/mysql的访问权限问题。下面的命令把/var/lib/mysql的拥有者改为当前用户:
1 | sudo chown -R openscanner:openscanner /var/lib/mysql |
如果报chown: 无效的用户: "openscanner:openscanner"
错误,更换命令,并用 ll 查看目录权限列表
1 | chown root /var/lib/mysql/ |
然后,重启服务:
1 | service mysqld restart |
登录重置密码:
1 | mysql -u root -p |
1 | mysql > use mysql; |
重启mysql服务
1 | service mysqld restart |
1 | firewall-cmd --zone=public --add-port=3306/tcp --permanent |
1、编辑mysql配置文件
1 | vim /etc/my.cnf |
2、在[mysqld]分段下添加一行:
1 | max_connections=10000 |
3、编辑/usr/lib/systemd/system/mysqld.service配置文件
4、在文件尾部添加2行:
1 | LimitNOFILE=65535 |
5、重启使mysql配置生效
1 | systemctl daemon-reload |
6、查看mysql最大连接数
1 | select @@max_connections; |
1、改表法
1 | mysql -u root -pvmwaremysql>use mysql; |
2、授权法
1 | GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; |
允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码
1 | GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; |
刷新权限使之生效
mysql>flush privileges;