You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
默认 MySQL 5.7 安装完有一个随机密码生成,位置在:/var/log/mysqld.log,里面有这样一句话:A temporary password is generated for root@localhost: 随机密码
如果初次要连上去需要填写该密码
我们也可以选择重置密码:
systemctl stop mysqld.service
/usr/sbin/mysqld --skip-grant-tables --user=mysql
在启动一个终端:mysql -u root mysql
UPDATE user SET authentication_string=PASSWORD('新密码') where USER='root';FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '上一步的新密码' WITH GRANT OPTION;
systemctl restart mysqld.service
试一下:mysql -h localhost -u root -p 然后输入密码,在 MySQL 终端输入:select 1;
如果报:You must reset your password using ALTER USER statement before executing this statement,解决办法:
set global validate_password_policy=0; #密码强度设为最低等级
set global validate_password_length=6; #密码允许最小长度为6
set password = password('新密码');
FLUSH PRIVILEGES;
YUM 安装的 MySQL 默认配置文件在:vim /etc/my.cnf,默认有如下信息,会自己配置的可以改下。
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid