Linux has just installed MySQL, tried to write a program to connect to MySQL, there are only local IP address to connect, and 127.0.0.1 and localhost can not access
Solve this problem main view 3 directions
1 does the. hosts have IP mappings 2. Is the user information in the Users table in the MySQL database correct
The direction I resolved,
1.hosts viewed the information with mapped 127.0.0.1 and localhost.
2. Incorrect user information
Here's the problem: Remember that the user and password are root when you first install it, and that configuring IP addresses through programs or other client software access is successful.
However, after exiting the system, the command is used locally (other clients, etc., are accessed properly)
Mysql-uroot-proot
No access, prompt password
1045 (28000for'root'@'localhost' (using password:yes)
Baffled ...
No way, only to re-modify the user password
Method 1
#/etc/init.d/--user=mysql--skip-grant-tables--skip-networking &-u root mysqlmysql > UPDATE User SET password=password ('newpassword'where user=' Root'; MySQL> FLUSH privileges;mysql>/etc/init.d/ -uroot-< Enter the newly created password newpassword>
Then in connection with MySQL, success. Problem solved perfectly, and localhost and 127.0.0.1 also have access to the
There may be other reasons.
Cause 2-Configuration file Error:
Check etc below the MY.CNF below:
#password = your_passwordport 3306socket =/usr/mysql-data/ for Some specific programs# the MySQL server[mysqld]port 3306socket =/ Usr/mysql-data/mysql.sock
There are several ways to change the password in MySQL
Method One
Using phpMyAdmin
(graphical management of MySQL database Tools), this is the simplest, directly with the SQL statement to modify the MySQL Database Library user table, but do not forget to use the password function, insert the user with the Insert command, modify the user with the update command, delete with delete command. A detailed description of the data table User field is later in this section.
Method Two
Use Mysqladmin. Input
Mysqladmin-u root-p OldPassword newpasswd
After executing this command, you need to enter the root's original password so that the root password will be changed to NEWPASSWD. Similarly, you can change your password by changing the root of the command to your username.
Of course, if your mysqladmin isn't connected to MySQL,
Server, or you have no way to execute mysqladmin, then this method is invalid, and mysqladmin cannot erase the password.
The following methods are used at the MySQL prompt and must have root privileges for MySQL:
Method Three
Mysql> INSERT into Mysql.user (Host,user,password) VALUES ('%','system ', PASSWORD ('manager'); MySQL> FLUSH privileges
Specifically, this is the addition of a user named system with a password of manager. Note To use the password function, and then use the flush
Privileges to perform the confirmation.
A solution that uses both localhost and 127.0.0.1 to connect under Linux