mysql第一次安装 无法登陆_mysql源码包安装完,mysql第一次不能登录及客户端不能连接mysql db问题...

1. 环境 OS: Centos 6.6(bit).

mysql源码:mysql-5.7.4-m14

2. mysql 安装完成后,因为mysql root用户密码为空,正常第一次mysql不加密码,可以直接登录. 此处mysql安装完,mysql不能直接登录,报异常

root@pretest packages]# mysql

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

用mysqladmin修改密码,也不能修改.

[root@pretest packages]# mysqladmin -u root -password mysql

mysqladmin: connect to server at 'localhost' failed

error: 'Access denied for user 'root'@'localhost' (using password: YES

3. 开两个ssh终端.

3.1 终端1,操作如下.停掉mysql服务.

[root@pretest ~]# service mysqld stop

/etc/init.d/mysqld: line 46: /usr/local/mysql: is a directory

/etc/init.d/mysqld: line 47: /data/mysqldb: is a directory

Shutting down MySQL.[  OK  ]

[root@pretest ~]#

[root@pretest ~]# mysqld_safe --skip-grant-tables &

[1] 2531

[root@pretest ~]# 141204 16:39:26 mysqld_safe Logging to '/usr/local/mysql/mysql_error.log'.

141204 16:39:26 mysqld_safe Starting mysqld daemon with databases from /data/mysqldb

3.2 终端2, 用mysql直接登录,修改mysql用户为root的密码.

root@pretest ~]# mysql -u root

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.7.4-m14 Source

Copyright (c) 2000, 2013, 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> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> update user set Password=PASSWORD('mysqltest') where user='root';

Query OK, 0 rows affected (0.00 sec)

Rows matched: 1  Changed: 0  Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.01 sec)

mysql>

mysql> quit

3.3 假如终端1为pts/0.

在终端2界面,kill掉终端1. pkill -KILL -t pts/0

3.4 终端2 启动mysql.

/etc/init.d/mysql start   (service mysqld start)

4.如上正常情况,密码忘记或mysql如上异常,都能解决.

此处修改完mysql root用户密码后, 用mysql -u root -p加密码登录,报刚修改的密码过期.查询mysql.user表中.root用户的password_expired栏位为Y,修改为N后OK.操作如下.

mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> select user,password,password_expired,password_lifetime from user where user='root';

+------+-------------------------------------------+------------------+-------------------+

| user | password                                  | password_expired | password_lifetime |

+------+-------------------------------------------+------------------+-------------------+

| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | Y                |              NULL |

+------+-------------------------------------------+------------------+-------------------+

1 row in set (0.00 sec)

mysql>

mysql>

mysql> update user set password_expired='N' where user='root';

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0

mysql>

mysql> select user,password,password_expired,password_lifetime from user where user='root';

+------+-------------------------------------------+------------------+-------------------+

| user | password                                  | password_expired | password_lifetime |

+------+-------------------------------------------+------------------+-------------------+

| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | N                |              NULL |

+------+-------------------------------------------+------------------+-------------------+

1 row in set (0.00 sec)

mysql>

mysql登录成功.

5. 客户端不能连接mysql db.报错Error 1045(28000): Access denied for user 'root'......

在mysql db mysql.user表中赋权限即可.

mysql> grant all privileges on *.* to 'root'@'%' identified by 'mysql123';

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql>

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28569596/viewspace-1356728/,如需转载,请注明出处,否则将追究法律责任。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值