That day, I wanted to deploy the database in mysql on another linux computer. However, I found that all the configurations were correct, that is, I couldn't connect to mysql. I returned an error saying that the permission was insufficient and the connection was disabled.
No way. Go to google to find the answer. Mysql databases do not support remote connections by default on linux Hosts.
The discovery is just one sentence. We need an authorization:
Grant all privileges on *. * to root @ "%" identified by "password ";
Although I have not started to contact the database, I have been learning English for a long time, this statement grants all operation permissions to the root user @ '%', which means it applies to any ip address.
In the past, this corresponds to modifying the data in the mysql. user table. You can compare the changes in the table content before and after the execution.
Linux users may also need to modify/etc/mysql/my. cnf
Comment out the following lines or enter the real ip address of the local machine. It is more convenient to directly comment out the machine that frequently changes the ip address. However, I still cannot comment out the differences between the two methods, tell me what you want to know.
# Bind-address = 127.0.0.1
After a long time, I used navicat to link mysql to open mysql and check that Chinese characters are garbled. I realized that it was definitely a problem of encoding methods. Set it to utf8 in the Link attribute of navicat.
Later, I checked that the default mysql encoding in linux is utf8, which is consistent with that in linux. Mysql uses latin1 if it is not changed in the win system. It is usually changed to GBK during installation.
It is not important to use navicat for a successful connection. You also need to implement remote connection in java.
I use the jdbc Method to link to the mysql database
In the driver, specify that the encoding is true and the UTF-8 encoding is used.
The Code is as follows:
Ct = DriverManager. getConnection ("jdbc: mysql: // localhost: 3306/bbs? User = root & password = asdasd & useUnicode = true & characterEncoding = utf8 ");
The methods in this article are not original and are widely used. The purpose of writing is only to record the key parts in development. I also hope you can give me a lot of comments.
This article is from the "walking all the way" blog