Chinaunix首页 | 论坛 | 博客
  • 博客访问: 62968
  • 博文数量: 11
  • 博客积分: 69
  • 博客等级: 民兵
  • 技术积分: 485
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-09 00:44
文章分类
文章存档

2013年(1)

2012年(6)

2011年(4)

分类:

2012-01-12 22:15:27

1. 在Ubuntu上安装完Mysql;
2.运行 $mysql 或者 $mysql -u root 命令均有如下错误信息提示:
Access denied for user 'root'@'localhost' (using password: NO)
出现这个错误的根本原因是安装Mysql后没有设置登录密码。

解决办法:

t@servert1 ~]$ /etc/init.d/mysqld stop
Stopping MySQL: [ OK ]

[root@servert1 ~]$ mysqld_safe --skip-grant-tables &

[root@servert1 ~]$ Starting mysqld daemon with databases from 
$sudo service mysql start

[root@servert1 ~]# mysql -u root

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 34
Server version: 5.1.49-1ubuntu8 (Ubuntu)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

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

mysql>update user set password=PASSWORD("testpass") where User='root';


ERROR 1046 (3D000): No database selected

mysql> show databases;

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

| Database |

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

| information_schema | 

| mysql | 

| test | 

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

3 rows in set (0.13 sec)



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> show tables;

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

| Tables_in_mysql |

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

| columns_priv | 

| db | 

| func | 

| help_category | 

| help_keyword | 

| help_relation | 

| help_topic | 

| host | 

| proc | 

| procs_priv | 

| tables_priv | 

| time_zone | 

| time_zone_leap_second | 

| time_zone_name | 

| time_zone_transition | 

| time_zone_transition_type | 

| user | 

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

17 rows in set (0.00 sec)



mysql> update user set password=PASSWORD("testpass") where User='root';

Query OK, 3 rows affected (0.05 sec)

Rows matched: 3 Changed: 3 Warnings: 0



mysql> flush privileges; 

Query OK, 0 rows affected (0.04 sec)



mysql> quit

Bye

[root@servert1 ~]# /etc/init.d/mysql restart

bash: /etc/init.d/mysql: No such file or directory

[root@servert1 ~]# /etc/init.d/mysqld restart

STOPPING server from pid file /var/run/mysqld/mysqld.pid

101120 04:17:15 mysqld ended



Stopping MySQL: [ OK ]

Starting MySQL: [ OK ]

[1]+ Done mysqld_safe --skip-grant-tables

[root@servert1 ~]# mysql -u root -p

Enter password: 

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

Your MySQL connection id is 2

Server version: 5.0.77 Source distribution



Type 'help;' or '\h' for help. Type '\c' to clear the buffer.



mysql> quit

Bye

[root@servert1 ~]#
阅读(2523) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~