Ubuntu 16.04 Install MySQL

Source: Internet
Author: User
Tags mysql in safe mode

1. Installation

12345 $ sudo apt-get install mysql-server$ apt install mysql-client$ apt install libmysqlclient-dev

Once installed, enter the following code to check if the installation was successful.

12345 $ sudo netstat -tap | grep mysql$ netstat -tap | grep mysqltcp6        0       0       [::]:mysql    [::]:*    LISTEN    7510/mysqld

If a third line of hints appears, the installation is successful.

2. Log in to MySQL

1 $ mysql -u root -p

Enter the password, if you can enter the following do not look;

If the prompt cannot be logged in, we try to enable Safe mode to log in to MySQL, so that you can bypass the password login, log in and then change the password.

3. Login to MySQL in safe mode

1234567 $ sudo /etc/init.d/mysql stop-------------------------------------[sudo] wl 的密码:[ ok ] Stopping mysql (via systemctl): mysql.service.$ sudo /usr/bin/mysqld_safe --skip-grant-tables --skip-networking &

Enter the first line to terminate the MySQL run, successful, will prompt the following two lines; Enter line fourth, success, without any error can open a terminal window for the next step, but generally error, such as prompt Mysqld_safe Directory '/var/run/ Mysqld ' for UNIX socket file don ' t exists

So we try to enter the following code

123 $ sudo mkdir -p /var/run/mysqld$ sudo chown mysql:mysql /var/run/mysqld

Finally, re-enter:

1 sudo /usr/bin/mysqld_safe --skip-grant-tables --skip-networking &

Here is not the prompt error, you can open another terminal port, try to login MySQL without password.

1 mysql -u root

We should be able to get into MySQL here and keep working.

1234567 > use mysql;updateusersetauthentication_string=PASSWORD("这里输入你要改的密码"whereUser=‘root‘; #更改密码update usersetplugin="mysql_native_password"; #如果没这一行可能也会报一个错误,因此需要运行这一行> flush privileges; #更新所有操作权限> quit;

4. Log in to MySQL with the modified password

After a series of actions above, you should be able to use the password you changed to log in.

1234 > sudo /etc/init.d/mysql stop> sudo /etc/init.d/mysql start # reset mysql> mysql -u root -p

The first line terminates the database run, the second row restarts the database service, and the third line is logged in.

Ubuntu 16.04 Install MySQL

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.