问题
I installed MySql on OpenWRT successfully without any errors - see below but I am having issues logging in - it's telling me access denied. But according to everything I found on the Internet, the default user name is root and there is no password so I must be a special case.
Please take a look below:
root@OpenWrt:~# mysql_install_db
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h OpenWrt password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/scripts/mysqlbug script!
root@OpenWrt:~#
I then start the server:
root@OpenWrt:~# /usr/bin/mysqld &
root@OpenWrt:~# 160104 10:48:04 [Note] Event Scheduler: Loaded 0 events
160104 10:48:04 [Note] /usr/bin/mysqld: ready for connections.
Version: '5.1.73' socket: '/var/run/mysqld.sock' port: 5158 Source distribution
Then I try to log on:
root@OpenWrt:~# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
root@OpenWrt:~#
I then tried:
root@OpenWrt:~# mysqladmin -u root -p root
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
root@OpenWrt:~#
In the above, for password I entered: "root" when it asked me for it. I also tried leaving it blank but no luck. I also tried ('new-password').
I have spent hours searching this site and other sites but none of the suggestions I've tried work. Also, in my case, mysqld_safe does not appear to be installed (and I don't believe it's available for OpenWRT).
Point of references: http://forums.mysql.com/read.php?34,140320,140324, http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html, How to find out the MySQL root password, 'Access denied for user 'root'@'localhost' (using password: NO)' and many other of which I lost track -- too many and none of them work.
Update
Please take a look below:
root@OpenWrt:~# /usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
root@OpenWrt:~# /usr/bin/mysqladmin -u root password 'root'
/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
root@OpenWrt:~# /usr/bin/mysqladmin -u root password 'admin'
/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
root@OpenWrt:~# mysqladmin reload
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
root@OpenWrt:~# /usr/bin/mysqladmin -u root password
/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
回答1:
Have you tried following the instructions it gives you after install? specifically:
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
It could be the case that there is no root user created or some such.
Also perhaps force a reload of the database, especially once you add a user to force it to reload the user table:
mysqladmin reload
HTH
回答2:
As mysql log file is suggesting, try below comamnd-
/usr/bin/mysqladmin -u root password 'your_root_password';
Even you can try without password as per below and set root password from mysql prompt-
mysql -uroot
回答3:
I fixed it! I found what the problem was!
MySql looks for the user name in its tables and if it keeps telling me "access denied" it means the "root" user most likely doesn't exist (since it is a brand new installation). So I removed the entire installation and deleted "everything" MySql associated.
I ran the install script with the --help option and check this out!
--user=user_name The login username to use for running mysqld. Files
and directories created by mysqld will be owned by this
user. You must be root to use this option. By default
mysqld runs using your current login name and files and
directories that it creates will be owned by you.
Then, I ran the script again but I passed the --user=root parameter:
mysql_install_db --user=root
root@OpenWrt:~# mysql_install_db --user=root
Voila! :)
root@OpenWrt:~# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73 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>
Having said this, now I am thinking, I could have probably searched the databases with a notepad or some sort of database editor since they are in ASCII format and see if I can find an entry for user root but the files are gone now. Either way, this is the solution!
来源:https://stackoverflow.com/questions/34589871/mysql-cant-log-in-access-denied-brand-new-installation-openwrt