安装mysql后,常规方法登录出现错误提示。直接:
/etc/my.cnf添加以下加粗的三句:
# 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 skip-grant-tables datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock port=3306 explicit_defaults_for_timestamp=true # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Recommended in standard MySQL setup sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
启动mysqld:【强制启动】
mysqld --user=root
最后,更改密码这些。
启动另一个窗口,然后:
步骤 1):输入命令mysql -uroot
步骤 2):输入use mysql;命令连接权限数据库。
步骤 3):输入命令update mysql.user set authentication_string=password('新密码') where user='用户名' and Host ='localhost';设置新密码。
步骤 4):输入 flush privileges; 命令刷新权限。
步骤 5):输入quit;命令退出 MySQL 重新登录,此时密码已经修改为刚才输入的新密码了。
重要的是,最后应该在/etc/my.cnf中加注释:
#skip-grant-tables