MYSQL登录错误:mysqladmin: connect to server

原创
2016/06/06 22:59
阅读数 446

最近安装mysql后,由于默认密码为空,也登陆不了,通过 mysqladmin –u root password  无法设置密码,一直提示如下错误

[root@maizi ~]# mysqladmin -u root password 'root'
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'

解决办法如下:

--skip-grant-tables:不启动grant-tables(授权表),跳过权限控制的作用

[root@maizi ~]# service mysqld stop
停止 mysqld:                                              [确定]
[root@maizi ~]# mysqld_safe --skip-grant-tables &
[2] 3207
[root@maizi ~]# 2016-06-06T14:17:46.748722Z mysqld_safe Logging to '/var/log/mysqld.log'.
2016-06-06T14:17:46.801232Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
 mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.13 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

还有一直方式就是在my.cnf配置文件中添加  skip-grant-tables

[root@maizi ~]# cat /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
#skip-grant-tables
[root@maizi ~]# 

成功登录mysql后就可以修改密码了,操作如下:

mysql> use mysql;
Database changed
mysql> update user set authentication_string=PASSWORD('123456') where user='root' and host='localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit;
Bye
[root@maizi ~]# mysql -uroot -p123456;
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.13

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

修改密码后确实可以登录了,当是登录基本上啥做不了,还需要重新设置一下密码

mysql> show database;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1
mysql> SET PASSWORD = PASSWORD('123456');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> SET PASSWORD = PASSWORD('maizi_123456');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> SET PASSWORD = PASSWORD('MAIzi_123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> 

ps:视乎我这个版本( 5.7.13 )的密码限定了密码规则,导致纯数字、纯字母都设置不成功,我估摸着至少必须包含字母大小写加数字吧。

展开阅读全文
打赏
0
0 收藏
分享
加载中
对的,就这么做的
2016/06/07 00:27
回复
举报
更多评论
打赏
1 评论
0 收藏
0
分享
返回顶部
顶部