#配置环境变量
[root@dxg-ml bin]# vim /etc/profile.d/mysqld.sh
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
#重载环境变量
[root@dxg-ml bin]#source /etc/profile.d/mysqld.sh
1.
2.
3.
4.
5.
6.
十二、登录数据库
1.首次登录数据库
#登录数据库
[root@dxg-ml bin]# /usr/local/mysql/bin/mysql --socket=/usr/local/mysql/data/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.24 MySQL Community Server - GPL
Copyright (c) 2000, 2021, 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>
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
2.常用命令登录数据库
#登录并配置远程登录
[root@dxg-ml bin]# mysql -P 13306 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.24
Copyright (c) 2000, 2021, 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.
root@localhost 18:35: [(none)]>
#查看数据库提示你必须重置你的密码
root@localhost 18:36: [(none)]> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
#修改数据库密码
root@localhost 18:36: [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.10 sec)
#再次查看数据库
root@localhost 18:38: [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.09 sec)
#使用数据库
root@localhost 18:38: [(none)]> use mysql;
Database changed
#这里就可以看到root@localhost这里的密码已经是mysql_native_password方式了
root@localhost 18:39: [mysql]> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host | user | authentication_string | plugin |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | mysql_native_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)
#创建一个远程用户登录
root@localhost 18:42: [mysql]> create user 'root'@'%' identified by 'root';
Query OK, 0 rows affected (0.24 sec)
root@localhost 18:43: [mysql]> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.06 sec)
root@localhost 18:44: [mysql]> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host | user | authentication_string | plugin |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| % | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | mysql_native_password |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | mysql_native_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
5 rows in set (0.00 sec)
#退出数据库
root@localhost 18:44: [mysql]> quit
Bye
[root@dxg-ml mysql-8.0.24]# ln -s /data/mysql-8.0.24/data /usr/local/mysql/
[root@dxg-ml mysql-8.0.24]# ln -s /data/mysql-8.0.24/log /usr/local/mysql/
[root@dxg-ml mysql-8.0.24]# ln -s /data/mysql-8.0.24/etc /usr/local/mysql/
#查看相关软连接
[root@dxg-ml mysql-8.0.24]# cd /usr/local/mysql/
[root@dxg-ml mysql]# ll
总用量 284
drwxr-xr-x 2 mysql mysql 4096 6月 9 19:06 bin
lrwxrwxrwx 1 root root 23 6月 10 09:54 data -> /data/mysql-8.0.24/data
drwxr-xr-x 2 mysql mysql 55 3月 26 03:42 docs
lrwxrwxrwx 1 root root 23 6月 10 09:54 etc -> /data/mysql-8.0.24/etc
drwxr-xr-x 3 mysql mysql 282 3月 26 03:42 include
drwxr-xr-x 6 mysql mysql 201 3月 26 03:42 lib
-rw-r--r-- 1 mysql mysql 274942 3月 22 16:44 LICENSE
lrwxrwxrwx 1 root root 22 6月 10 09:54 log -> /data/mysql-8.0.24/log
drwxr-xr-x 4 mysql mysql 30 3月 26 03:42 man
-rw-r--r-- 1 mysql mysql 666 3月 22 16:44 README
drwxr-xr-x 28 mysql mysql 4096 3月 26 03:42 share
drwxr-xr-x 2 mysql mysql 77 3月 26 03:42 support-files
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
6.重启服务
#1.重启服务
[root@dxg-ml mysql]# systemctl restart mysqld.service
#2.查看服务状态
[root@dxg-ml mysql]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since 四 2021-06-10 10:01:40 CST; 5s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 22307 (mysqld_safe)
CGroup: /system.slice/mysqld.service
├─22307 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/etc/my.cnf
└─23949 /usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/loca...
6月 10 10:01:40 dxg-ml systemd[1]: Started MySQL Server.
6月 10 10:01:40 dxg-ml systemd[1]: Starting MySQL Server...
6月 10 10:01:41 dxg-ml mysqld_safe[22307]: 2021-06-10T02:01:41.972907Z mysqld_safe Logging to '/usr/local/mysql/log/error.log'.
6月 10 10:01:41 dxg-ml mysqld_safe[22307]: 2021-06-10T02:01:41.991896Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
7.登录数据库
[root@dxg-ml mysql]# mysql -P 13306 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.24 MySQL Community Server - GPL
Copyright (c) 2000, 2021, 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.
root@localhost 10:02: [(none)]>
root@localhost 10:02: [(none)]>
root@localhost 10:02: [(none)]>
root@localhost 10:02: [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.18 sec)
root@localhost 10:02: [(none)]>
root@localhost 10:02: [(none)]>
root@localhost 10:02: [(none)]>
root@localhost 10:02: [(none)]> quit
Bye