Install and configure MySQL 2 in Ubuntu

Source: Internet
Author: User
Tags mysql command line

1. Install MySql in Ubuntu

Enter sudo apt-Get install mysql-server in the Ubuntu command lineYou can install the MySQL service. By default, the 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 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: sudo/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 ServiceAdd to auto start

Add boot auto-start:
Sudo update-rc.d MySQL defaults

Remove from Automatic startup:
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.

Now, you can remotely connect to MySQL In 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.