Mysql common error _ MySQL

Source: Internet
Author: User
Mysql common error 1: java. SQL. SQLException: null, message from server: is not allowed to connect to this MySQL server"

Solution:

The result is as follows:

So how should we solve this problem?

I also checked the information to solve this problem ....

In fact, the principle is very simple, that is, remote machine B does not allow machine A to access his database. That is to say, to solve this problem, we need to allow the database of Machine B

Machine A's access is done;

The procedure is also very simple:

1. open the mysql console and enter:

1 use mysql; 2 3 show tables;

II. input:

1 select host from user; 2 3 update user set host ='%' where user ='root';

3. enter the computer service interface and restart the mysql service ..

4. run the following command:

The return value is 1, indicating that the program runs normally... and wish you good luck ....

There is also a multi-method: http://hi.baidu.com/soutnila/item/5356f2c0002781bf0d0a7bae

Error 2: Access denied for user (using password: YES)

Solution:

First:

Warning: mysql_connect () [function. mysql-connect]: Access denied for user 'root' @ 'localhost' (using password: YES) in c: InetpubwwwrootclasscoreIBMysql. php on line 51
Mysql error:
1045: Access denied for user 'root' @ 'localhost' (using password: YES)
The username and password in the database connection file are incorrect.

Change the username and password of your mysql account in config. php.

Enter the root password for the account.

Second:

When you log on with mysql-uroot-p, the system prompts ERROR 1045: Access denied for user 'root' @ 'localhost' (usingpassword: YES). First, you can check whether the password is incorrect. I remember that I set a password of 123 for the root account during compilation, but not for the root account. You cannot log on directly using mysql-uroot, so you want to reset the password as follows:

1. stop mysql service: service mysql stop(It is best not to use killall-TERM mysql, which may cause damage to the data table)

2. log on without checking permissions: # bin/mysqld_safe -- skip-grant-tables & (enter the directory where you installed mysql to run this command, for example, if you do not want to enter the installation directory, you can directly enter/usr/local/mysql/bin/mysqld_safe -- skip-grant-tables &)

3. log on with an empty password and press enter to log on to mysql: # bin/mysql-uroot-p (same as above)

4. manually update the user table in the mysql database to set the new password: mysql> update mysql. user set password = password ("the password you want to set") where user = "username, use root here ";

5. refresh the mysql system permission table for the password to take effect: mysql> flush privileges;

6. exit: mysql> exit;

7. restart the mysql service: service mysql restart

Use the new password to log on. you can log on normally.

Of course, this method can also be used to solve the problem of forgetting the mysql password. (Reprinted address: http://chhenji.blog.163.com/blog/static/1332713172010510238041)

Problem 3: mysql inserts Chinese garbled code solution

Method:

MySQL 4.1 Character Set Support has two aspects: Character set and Collation ). The support for character sets is refined to four levels: server, database, table, and connection ). The following sections decode the server code, database code, data table code, and connection code to prevent Chinese garbled characters.

1. server encoding settings

The server encoding settings are as follows:

First, when installing mysql, there will be a step to select the encoding method, then select gbk. If not selected, the default encoding is latin1;

Second, after installing and playing with mysql, manually modify its configuration file as follows:

(1) modify my. ini (MySql Server Instance Configuration file) under the MySQL installation directory ). Set

Default-character-set = gbk (note: There are 2 places)
(2) modify the database. opt configuration file default-character-set = gbk default-collation = gbk_chinese_ci under the corresponding database directory in the data directory to restart the database, and close the console window to log on to the database again. 2. encoding of the database, data table, and connection section 2.1 set the encoding of the database and data table to solve the garbled problem, you must first find out the encoding used for the database and data table. If not specified, the default value is latin1.
The most commonly used character sets are gb2312, gbk, and utf8.
How to specify the character set of databases and data tables? The following example uses gbk:
[Create a database in MySQL Command Line Client]
Mysql> create table 'mysqlcode '(
-> 'Id' TINYINT (255) unsigned not null AUTO_INCREMENT primary key,
-> 'Content' VARCHAR (255) NOT NULL
->) TYPE = myisam character set gbk COLLATE gbk_chinese_ci;
Query OK, 0 rows affected, 1 warning (0.03 sec)
TYPE = myisam character set gbk COLLATE gbk_chinese_ci;
Is to specify the character set of the database, COLLATE (), so that mysql supports multiple encoding databases at the same time.
You can also use the following command to modify the character set of the database data table:
Alter database mysqlcode default character set 'gbk '.
The encoding of servers, databases, and data tables has been set before. the encoding in the database is gbk, and Chinese characters can be stored. However, if you want to execute insert or select operations, Chinese garbled characters will still occur, because the encoding of "connection" has not been set, database operations, such as insert and select, all include database connection actions. If you do not believe it, run the following SQL statement to try it: mysql> insert into mysqlcode values (null, 'Java hobby ');
Press enter and the result is as follows: ERROR 1406 (22001): Data too long for column 'content' at row 1
2.2 set the connection encoding to the server, database, and data table encoding. the connection encoding must be set. The connection encoding settings are as follows: mysql> SET character_set_client = 'gbk ';
Mysql> SET character_set_connection = 'gbk'
Mysql> SET character_set_results = 'gbk'
After configuring the connection encoding, you can successfully insert Chinese characters: mysql> insert into mysqlcode values (null, 'Java hobby ');
Query OK, 0 rows affected (0.02 sec)
In fact, the preceding three commands for connection encoding can be simplified to one: mysql> set names 'gbk'. after the connection encoding is set, Chinese characters can be correctly displayed during select queries: mysql> select * from mysqlcode;
+ ---- + ----------- +
| Id | content |
+ ---- + ----------- +
| 1 | java hobbies |
+ ---- + ----------- +
1 row in set (0.00 sec) 3 complete example below we will use an example to completely demonstrate the above theory, and finally achieve the goal of inserting Chinese characters into mysql: 3.1 to set mysql server encoding, See section 1 above. after installing mysql, modify my. ini and dataTable. create a database in the database encoded as gbk 3.2 first connect to the local database: mysql-h localhost-u root-proot, and then create a database: mysql> create database test; 3.3 create a data table and set its encoding-Chinese encoding test data table use test
Drop table if exists 'test'. 'test _ nml ';
SET @ saved_cs_client =@@ character_set_client;
SET character_set_client = gbk;
Create table 'test'. 'test _ nml '(
'Id' TINYINT (255) unsigned not null AUTO_INCREMENT primary key,
'Content' VARCHAR (255) NOT NULL
) ENGINE = InnoDB default charset = gbk COMMENT = 'User basic information ';
SET character_set_client = @ saved_cs_client; the red part here is equivalent to TYPE = myisam character set gbk COLLATE gbk_chinese_ci; 3.4 insert Chinese data -- insert data
SET @ saved_cs_client =@@ character_set_client;
Set names gbk;
Insert into test_nml values (null, 'I am Chinese'); Note: Each time you perform an insert, update, or select join operation, you must set the encoding, that is, add: set names 'gbk ';

I use mysql-5.0.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.