2

I seem to have forgotten my password to login as root user for MySql, in terminal (mac). I have consulted the mysql documentation at http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html, this however doesn't seem to work for me. What could I possibly do next?

user$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Here are the current databases available to me w. MySql database doesn't seem to appear there. Why is this?

user$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.6.13 Source distribution

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

+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+
4

1 回答 1

1

I've personally never been able to get the ini or text file method to work to send other commands in when resetting.

The generic instructions under C.5.4.1.3. Resetting the Root Password: Generic Instructions from that hyperlink are usually the way I find to work.

To change your root password:

  1. Stop mysqld if it is currently running.
  2. Start mysqld in "safe mode" using the --skip-grant-tables command line option. (Note: it's advised if possible to use the --skip-networking option as well if possible to avoid opening up access to your database server to the rest of the network / Internet while you do this!!)

    This will start the mysql daemon.

  3. Open your preferred mysql client and login as root with no password or type mysql -u root at the terminal. You shouldn't need a password because the grant tables have been skipped.

    You should now be able to log into the mysql server and be presented with the MOTD / welcome message.

  4. Run these SQL commands (Note: remember the trailing semicolon!)

    use mysql;
    
    update user SET Password=PASSWORD('MyNewPass') WHERE User='root';
    FLUSH PRIVILEGES;
    
  5. Exit the mysql client

  6. Stop the mysqld daemon - Important! If you don't stop the daemon then the database server will continue to operate with open permissions!!

  7. Restart the mysqld daemon under normal circumstances.

To answer your question:

Here are the current databases available to me w. MySql database doesn't seem to appear there. Why is this?

You see only those databases for which you have some kind of privilege, unless you have the global SHOW DATABASES privilege.

See: MySQL SHOW DATABASES Documentation

于 2013-12-10T09:42:56.490 回答