Remote connection to mysql from the MiniBBS series (MVC)

Source: Internet
Author: User

 

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

Related Article

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.