[root@zhnagguolong-virtual-machine:/#] sudo apt-get install mysql-server #安装mysql
[root@zhnagguolong-virtual-machine:/#] systemctl status mysql #查看mysql的状态
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2022-10-02 23:55:59 CST; 2min 8s ago
Process: 6313 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 6321 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 4584)
Memory: 361.7M
CPU: 2.361s
CGroup: /system.slice/mysql.service
└─6321 /usr/sbin/mysqld
[root@zhnagguolong-virtual-machine:/#] sudo mysql #进入数据库
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.30-0ubuntu0.22.04.1 (Ubuntu)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host,user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | debian-sys-maint |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
5 rows in set (0.00 sec)
mysql>update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select host,user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | debian-sys-maint |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+------------------+
5 rows in set (0.01 sec)
mysql>FLUSH PRIVILEGES; #刷新权限
mysql> alter user 'root'@'%' identified with mysql_native_password by '123456'; #修改mysql的密码,在这里密码假设设为123456,可以根据自己的想法修改
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES; #刷新
Query OK, 0 rows affected (0.00 sec)
mysql>exit #退出数据库
[root@zhnagguolong-virtual-machine:/#] mysql -u root -p #修改完密码后,重启进入数据库
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> FLUSH PRIVILEGES; #刷新
mysql>exit #退出数据库
[root@zhnagguolong-virtual-machine:/#] vim etc/mysql/mysql.conf.d/mysqld.cnf #修改配置文件
找到这一行:bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
将其修改为:bind-address = 0.0.0.0
mysqlx-bind-address = 0.0.0.0
[root@zhnagguolong-virtual-machine:/#] service mysql restart #重启mysql
[root@zhnagguolong-virtual-machine:/#] ifconfig #查看Ubuntu系统ip地址
[root@zhnagguolong-virtual-machine:/#] telnet ip地址 3306 #远程登录
Trying ip...
Connected to ip.
Escape character is '^]'.
[
8.0.30-0ubuntu0.22.04.1
tGiC<{!�q6fzn6>=caching_sha2_password2#08S01Got timeout reading communication packetsConnection closed by foreign host.
代表已经连接成功
Ubuntu系统安装数据库(MySQL)8.0版本并授权Navicat进行远程登录
于 2023-11-23 20:31:24 首次发布