Install MySQL under Ubuntu

Source: Internet
Author: User
Tags mysql client mysql version

Introduced

MySQL is an open-source database management system that is usually installed as part of the popular lamp (Linux,apache,mysql,php/python/perl) stack. It uses relational databases and SQL (Structured Query Language) to manage its data.

The installation is simple: Update the package index, install the Mysql-server package, and then run the included security script.

sudo apt-get updatesudo apt-get install mysql-server sudo mysql_secure_installation

This tutorial will show you how to install MySQL version 5.7 on an Ubuntu 16.04 server. However, if you want to update your existing MySQL installation to version 5.7, you can read this MySQL 5.7 update guide.

Step to install MySQL

In Ubuntu 16.04, by default, only the latest version of MySQL is included in the APT package repository. At the time of this writing, it was MySQL 5.7

To install it, simply update the package index on the server and install the default package Apt-get.

sudo apt-get updatesudo apt-get install mysql-server

You will be prompted to create the root password during the installation process. Choose a secure password and make sure you remember it because you need it later. Next, we will complete the configuration of MySQL.

Step to configure MySQL

Because it is a new installation, you need to run the accompanying security script. This will change some of the less secure default options, such as remote root logins and sample users. On older versions of MySQL, you will need to manually initialize the data directory, but MySQL 5.7 is done automatically.

Run the security script.

sudo mysql_secure_installation

This will prompt you to enter the root password that you created in step 1. You can press Y, and then ENTER to accept the default values for all subsequent problems, but ask if you want to change the root password. You only need to set it up in step 1, so you don't need to change it now.

Finally, let's test the MySQL installation.

Step 3– test MySQL

After the installation is done by the top, MySQL should have started to run automatically. To test it, check its status.

systemctl status mysql.service

You will see output similar to the following:

mysql.service - MySQL Community ServerLoaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en Active: active (running) since Wed 2016-11-23 21:21:25 UTC; 30min ago Main PID: 3754 (mysqld) Tasks: 28 Memory: 142.3M CPU: 1.994s CGroup: /system.slice/mysql.service └─3754 /usr/sbin/mysqld

If MySQL is not running, you can start it:

sudo systemctl mysql start

1.重启Mysql:service mysql restart
2.进入mysql:
-uroot- P
3. Set Allow remote access: GRANT all privileges on * * to ' root ' @ '% ' identified by ' qq564425 ' with GRANT OPTION;
If the above command appears: Error 1819 (HY000): Your password does not satisfy the current policy requirements
Execute the following command:mysql> set global validate_password_policy=0;
If you cannot connect remotely: sudo vi/etc/mysql/mysql.conf.d/mysqld.cnf
Comment out bind-address= 127.0.0.1 save restart
4. Modify the character encoding:

Configure the character encoding for MySQL under Ubuntu. After installing MySQL, the system default character encoding is latin1, the input is Chinese, but the output is a bunch of garbled. Now all we have to do is set MySQL's default character encoding to support Chinese encoding, such as GBK, GB23112, and so on.

First enter the directory where MySQL stores the configuration files

~ #cd  /etc/mysql/  

Execute ls to view the files under this folder

~ #ls  

Will find a file that is my.cnf, this file is a MySQL configuration file

Open this file with vim

~ #vi  MY.CNF  

After opening my.cnf, you will find two lines at the end of this file (this configuration file also references the other two profiles, we need to modify the MYSQLD.CNF, this is the MySQL server base configuration file):

!INCLUDEDIR/ETC/MYSQL/CONF.D  !INCLUDEDIR/ETC/MYSQL/MYSQL.CONF.D  

Open the/etc/mysql/mysql.conf.d/mysqld.cnf file with vim (if the prompt is not editable, you can switch the account to root)

~ #vi/etc/mysql/mysql.conf.d/mysqld.cnf  

After opening the file, under [Mysqld] skip-external-locking, add the Character-set-server=utf8

......  [Mysqld]  ......  skip-external-locking  Character-set-server=utf8  ...  

Below, we also go to set the client's default encoding, we now enter the MySQL client configuration file directory

~ #cd/etc/mysql/conf.d  ~ #ls  

LS, we found a file mysql.cnf

Open with VI and insert a line under [MySQL]: Default-character-set=utf8

~ #vi mysql.cnf    [MySQL]  Default-character-set=utf8  

Finally, restart the MySQL service

~ #service mysql Restart  

Go to MySQL and use \s to see if the changes were successful

Mysql>\s ...  Server     Characterset:utf8  Db         characterset:utf8  Client     characterset:utf8  Conn.      Characterset:utf8 ...    





Install MySQL under Ubuntu

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.