MySQL installation and remote connection configuration in Ubuntu

Source: Internet
Author: User
For MySQL installation in Ubuntu, enter sudoapt-getinstallmysql-server in the Ubuntu command line to install the mysql service,

For MySQL installation in Ubuntu, enter sudo apt-get install mysql-server in the Ubuntu command line to install the mysql service. By default,

1. Install MySQL in Ubuntu

Enter sudo apt-get install mysql-server in the Ubuntu command line to install the mysql service. By default, mysql-client is automatically installed when mysql-server is installed.

The installed mysql configuration file is located at/etc/mysql/my. cnf.

The shortcut icon for starting mysql is/etc/init. d/mysql.

Ii. Solution to coding problems

View the current MYSQL character Set [run in mysql command line mode]: show variables like 'character % ';

Change the encoding: sudo vim/etc/mysql/my. cnf

Find the [client] and add the following two sentences:

// The default character set is utf8.

Default-character-set = utf8

Find [mysqld] and add the following four sentences: (Note that there cannot be spaces before and after each line)

// The default character set is utf8.

Default-character-set = utf8

// Set utf8 encoding when connecting to the mysql database to run the mysql database as utf8

Init_connect = 'set NAMES utf8'

Finally, switch to vim's last line mode and run wq to exit the vim editor.

Stop Database Service: sudo/etc/init. d/mysql stop

Restart: s udo/etc/init. d/mysql start

Enter the database: mysql-uroot-p (your password)

View the encoding: show variables like '% character % ';

At this time, it should be all UTF-8 encoded.

Iii. MySQL service is automatically started upon startup

Add boot auto-start: sudo update-rc.d mysql ults

Remove from auto-boot: sudo update-rc.d-f mysql remove

4. Remotely connect to MySQL under ubuntu

Find vim/etc/mysql/my. cnf

Bind-address = 127.0.0.1

Comment out this line (as shown below)

# Bind-address = 127.0.0.1

Or change

Bind-address = 0.0.0.0

Allow access from any IP address or specify an IP address.

Restart MySQL

Sudo/etc/init. d/mysql restart

Authorize users to connect remotely

Grant all privileges on *. * to root @ "%" identified by "password" with grant option;

Flush privileges;

The command on the first line is interpreted as follows, *. *: The first * indicates the database name, and the second * indicates the table name. This means that all tables in all databases are authorized to users. Root: grant the root account. "%": Indicates that the authorized user's IP address can be specified. This indicates that any IP Address can access the MySQL database. "Password": password corresponding to the allocated account. Replace the password with your mysql root Account password.

The second command is to refresh the permission information, that is, to make the settings take effect immediately.

In this case, you can remotely connect to MySQL under ubuntu.

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.