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 mysql tcp6 0 0 [::]:mysql [::]:* LISTEN 7510/mysqld |
If a third line of hints appears, the installation is successful.
2. Log in to MySQL
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.
We should be able to get into MySQL here and keep working.
1234567 |
> use mysql;
>
update
user
set
authentication_string=
PASSWORD
(
"这里输入你要改的密码"
)
where
User
=
‘root‘
; #更改密码
>
update user
set
plugin=
"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