Summary of mysql remote database connection methods

Source: Internet
Author: User
There are many methods to connect to the database in mysql. If you download the connection directly in mysql command mode, we can divide it into a local connection and a remote connection, and the other is to connect in php mode, I will introduce it one by one.

There are many methods to connect to the database in mysql. If you download the connection directly in mysql command mode, we can divide it into a local connection and a remote connection, and the other is to connect in php mode, I will introduce it one by one.

In mysql command mode, connect to mysql as follows:

The Code is as follows:

Mysql-h host address-u user name-p User Password

1. Connect to MYSQL on the local machine.

First open the DOS window, and then enter the directory mysqlbin,

The Code is as follows:

1. d: mysqlbin> mysql-h localhost-u root
// You can access the MySQL server.
2. mysql> grant all privileges on *. * TO GRANT OPTION
// Grant data access permissions to any host
3. mysql> FLUSH PRIVILEGES
// The modification takes effect.
4. mysql> EXIT
// Exit the MySQL server

2. Connect to MYSQL on the remote host. Assume that the IP address of the remote host is 110.110.110.110, the user name is root, and the password is abcd123. Enter the following command:

The Code is as follows:

Mysql-h110.110.110.110-u root-p 123)

3. exit MYSQL command: exit (Press ENTER)

The mysql command mode is introduced above. Let's look at the php connection.

In PHP, this task is completed through the mysql_connect () function.

Syntax

The Code is as follows:

Mysql_connect (servername, username, password );

Example

The Code is as follows:

$ Mysql_server = "localhost ";
$ Mysql_username = "root ";
$ Mysql_password = "root ";
$ Mysql_dbname = "flsp ";
$ Con = mysql_connect ($ mysql_server, $ mysql_username, $ mysql_password) or die ('could not connect to mysql server! ');

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.