[Database] Ubuntu18.04 install MySQL Comments

00. Contents

01. Install MySQL

1.1 software update source

deng@itcast:~$ sudo apt update 

1.2 Installation mysql-server

deng@itcast:~$ sudo apt install mysql-server
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
下列软件包是自动安装的并且现在不需要了:
  libnginx-mod-http-geoip libnginx-mod-http-image-filter
  libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream nginx-common
  nginx-core
使用'sudo apt autoremove'来卸载它(它们)。
将会同时安装下列软件:
  libaio1 libevent-core-2.1-6 libhtml-template-perl mysql-client-5.7
  mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7
建议安装:
  libipc-sharedcache-perl mailx tinyca
下列【新】软件包将被安装:
  libaio1 libevent-core-2.1-6 libhtml-template-perl mysql-client-5.7
  mysql-client-core-5.7 mysql-common mysql-server mysql-server-5.7
  mysql-server-core-5.7
升级了 0 个软件包,新安装了 9 个软件包,要卸载 0 个软件包,有 635 个软件包未被升级。
需要下载 19.1 MB 的归档。
解压缩后会消耗 155 MB 的额外空间。
您希望继续执行吗? [Y/n] 

1.3 Installation libmysqlclient-dev

deng@itcast:~$ sudo apt install libmysqlclient-dev
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
下列软件包是自动安装的并且现在不需要了:
  libnginx-mod-http-geoip libnginx-mod-http-image-filter
  libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream nginx-common
  nginx-core
使用'sudo apt autoremove'来卸载它(它们)。
将会同时安装下列软件:
  libmysqlclient20 libssl-dev libssl1.1 zlib1g-dev
建议安装:
  libssl-doc

02. Configure MySQL

Run the following command

deng@itcast:~$ sudo mysql_secure_installation 

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
#1. 选择N
Press y|Y for Yes, any other key for No: N

#2. 设置密码
Please set the password for root here.

New password: 

Re-enter new password: 

#3. 是否移除用户
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : N

 ... skipping.

#4. 不允许root远程登录
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.
#5. 是否移除test数据库
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N

 ... skipping.
 
#6. 重新加载表
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done! 
deng@itcast:~$ 

03. Check out the MySQL status

Display active representation is already running

deng@itcast:~$ systemctl status mysql.service
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled
   Active: active (running) since Sat 2020-02-29 22:00:07 CST; 9min ago
 Main PID: 6032 (mysqld)
    Tasks: 29 (limit: 2292)
   CGroup: /system.slice/mysql.service
           └─6032 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

2月 29 22:00:07 itcast systemd[1]: Starting MySQL Community Server...
2月 29 22:00:07 itcast systemd[1]: Started MySQL Community Server.

04. Configure remote access MySQL

Under MySQL in Ubuntu by default only allow local access, if necessary third-party tools you need to configure MySQL connection.

Log in MySQL 4.1 database

deng@itcast:~$ sudo mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

4.2 Authorization (has all the permissions for all database)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> 

4.3 refresh permission

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> 

05. Analysis

Question 1

ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.13.143' (111)

Solution:

The mysql configuration file bind-address = 127.0.0.1commenting out

deng@itcast:~$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 

 41 # Instead of skip-networking the default is now to listen only on
 42 # localhost which is more compatible and is not less secure.
 43 #bind-address       = 127.0.0.1

Question 2

ERROR 1045 (28000): Access denied for user 'root'@'192.168.13.143' (using password: YES)

Solution

Add "skip-grant-tables" in [mysqld] to skip any line behind the password verification process

[mysqld]
#
# * Basic Settings
#
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
skip-grant-tables

change Password

mysql> use mysql
Database changed
mysql> update user set authentication_string=password('123456') where user='root';
Query OK, 2 rows affected, 1 warning (0.01 sec)
Rows matched: 2  Changed: 2  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.09 sec)

mysql> 

Remove just added "skip-grant-tables" and then reboot

deng@itcast:~$ sudo systemctl restart mysql
deng@itcast:~$ mysql -h 192.168.13.143 -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye

06. Appendix

Published 641 original articles · won praise 2518 · Views 860,000 +

Guess you like

Origin blog.csdn.net/dengjin20104042056/article/details/104584837