Ubungu 18.04安装MySQL 5.7.24

Ubuntu 18.04,mysql Ver 14.14 Distrib 5.7.24, for Linux (x86_64),

USERNAME@USERNAME-VirtualBox:~$ sudo apt-get install -y mysql-server mysql-client
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libaio1 libevent-core-2.1-6 libhtml-template-perl mysql-client-5.7
mysql-client-core-5.7 mysql-server-5.7 mysql-server-core-5.7
Suggested packages:
libipc-sharedcache-perl mailx tinyca
The following NEW packages will be installed:
libaio1 libevent-core-2.1-6 libhtml-template-perl mysql-client mysql-client-5.7
mysql-client-core-5.7 mysql-server mysql-server-5.7 mysql-server-core-5.7
0 upgraded, 9 newly installed, 0 to remove and 204 not upgraded.
Need to get 20.4 MB of archives.
After this operation, 160 MB of additional disk space will be used.
Get:1 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libaio1 amd64 0.3.110-5 [6,448 B]
Get:2 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 mysql-client-core-5.7 amd64 5.7.24-0ubuntu0.18.04.1 [6,988 kB]
Get:3 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 mysql-client-5.7 amd64 5.7.24-0ubuntu0.18.04.1 [2,312 kB]
Get:4 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 mysql-server-core-5.7 amd64 5.7.24-0ubuntu0.18.04.1 [7,777 kB]
Get:5 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libevent-core-2.1-6 amd64 2.1.8-stable-4build1 [85.9 kB]
Get:6 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 mysql-server-5.7 amd64 5.7.24-0ubuntu0.18.04.1 [3,193 kB]
Get:7 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libhtml-template-perl all 2.97-1 [59.0 kB]
Get:8 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 mysql-client all 5.7.24-0ubuntu0.18.04.1 [9,828 B]
Get:9 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 mysql-server all 5.7.24-0ubuntu0.18.04.1 [9,948 B]
Fetched 20.4 MB in 8s (2,540 kB/s)
Preconfiguring packages ...
Selecting previously unselected package libaio1:amd64.
(Reading database ... 156461 files and directories currently installed.)
Preparing to unpack .../0-libaio1_0.3.110-5_amd64.deb ...
Unpacking libaio1:amd64 (0.3.110-5) ...
Selecting previously unselected package mysql-client-core-5.7.
Preparing to unpack .../1-mysql-client-core-5.7_5.7.24-0ubuntu0.18.04.1_amd64.deb ...
Unpacking mysql-client-core-5.7 (5.7.24-0ubuntu0.18.04.1) ...
Selecting previously unselected package mysql-client-5.7.
Preparing to unpack .../2-mysql-client-5.7_5.7.24-0ubuntu0.18.04.1_amd64.deb ...
Unpacking mysql-client-5.7 (5.7.24-0ubuntu0.18.04.1) ...
Selecting previously unselected package mysql-server-core-5.7.
Preparing to unpack .../3-mysql-server-core-5.7_5.7.24-0ubuntu0.18.04.1_amd64.deb ...
Unpacking mysql-server-core-5.7 (5.7.24-0ubuntu0.18.04.1) ...
Selecting previously unselected package libevent-core-2.1-6:amd64.
Preparing to unpack .../4-libevent-core-2.1-6_2.1.8-stable-4build1_amd64.deb ...
Unpacking libevent-core-2.1-6:amd64 (2.1.8-stable-4build1) ...
Selecting previously unselected package mysql-server-5.7.
Preparing to unpack .../5-mysql-server-5.7_5.7.24-0ubuntu0.18.04.1_amd64.deb ...
Unpacking mysql-server-5.7 (5.7.24-0ubuntu0.18.04.1) ...
Selecting previously unselected package libhtml-template-perl.
Preparing to unpack .../6-libhtml-template-perl_2.97-1_all.deb ...
Unpacking libhtml-template-perl (2.97-1) ...
Selecting previously unselected package mysql-client.
Preparing to unpack .../7-mysql-client_5.7.24-0ubuntu0.18.04.1_all.deb ...
Unpacking mysql-client (5.7.24-0ubuntu0.18.04.1) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../8-mysql-server_5.7.24-0ubuntu0.18.04.1_all.deb ...
Unpacking mysql-server (5.7.24-0ubuntu0.18.04.1) ...
Setting up libevent-core-2.1-6:amd64 (2.1.8-stable-4build1) ...
Setting up libhtml-template-perl (2.97-1) ...
Processing triggers for ureadahead (0.100.0-20) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Setting up libaio1:amd64 (0.3.110-5) ...
Processing triggers for systemd (237-3ubuntu10.9) ...
Processing triggers for man-db (2.8.3-2) ...
Setting up mysql-client-core-5.7 (5.7.24-0ubuntu0.18.04.1) ...
Setting up mysql-server-core-5.7 (5.7.24-0ubuntu0.18.04.1) ...
Setting up mysql-client-5.7 (5.7.24-0ubuntu0.18.04.1) ...
Setting up mysql-client (5.7.24-0ubuntu0.18.04.1) ...
Setting up mysql-server-5.7 (5.7.24-0ubuntu0.18.04.1) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Renaming removed key_buffer and myisam-recover options (if present)
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
Setting up mysql-server (5.7.24-0ubuntu0.18.04.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for systemd (237-3ubuntu10.9) ...
Processing triggers for ureadahead (0.100.0-20) ...
USERNAME@USERNAME-VirtualBox:~$ mysql -uroot -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
USERNAME@USERNAME-VirtualBox:~$ mysql -uroot -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

Ubuntu上 MySQL安装后,无法访问服务器,

USERNAME@USERNAME-VirtualBox:~$ whereis mysql
mysql: /usr/bin/mysql /usr/lib/mysql /etc/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

参考:
ubuntu18.04 安装mysql不出现设置 root 帐户的密码问题
https://blog.csdn.net/NeptuneClouds/article/details/80995759
update mysql.user set authentication_string=password('password') where user='root'and Host = 'localhost';


更改root账号密码
mysql> select host,user from mysql.user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | debian-sys-maint |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
4 rows in set (0.00 sec)

mysql>
mysql> update mysql.user set authentication_string=password("") where user = 'root' and host = 'localhost';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

mysql> update mysql.user set authentication_string=password("111111") where user = 'root' and host = 'localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1

更改root账号的plugin:为什么?更改后可以不需要添加sudo即可使用mysql登录,
mysql> select user,host,authentication_string,plugin from user where user = 'root';
+------+-----------+-------------------------------------------+-------------+
| user | host | authentication_string | plugin |
+------+-----------+-------------------------------------------+-------------+
| root | localhost | *FD571203974BA9AFE270FE62151AE967ECA5E0AA | auth_socket |
+------+-----------+-------------------------------------------+-------------+
1 row in set (0.00 sec)

mysql> update user set plugin='mysql_native_password' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

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

猜你喜欢

转载自www.cnblogs.com/luo630/p/10237142.html
今日推荐