[root@centos7 ~]# mysql -S /mysqldb/3307/socket/mysql.sock # 使用-S指定套接字文件
Server version: 10.2.15-MariaDB-log Source distribution
MariaDB [(none)]> show variables like '%port'; # 查看端口是否是3306
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| extra_port | 0 |
| innodb_deadlock_report | full |
| large_files_support | ON |
| port | 3307 |
| report_port | 3307 |
| require_secure_transport | OFF |
+--------------------------+-------+
6 rows in set (0.001 sec)
[root@centos7 ~]# mysql -S /mysqldb/3308/socket/mysql.sock #再连接测试一下3307和3308
Server version: 10.2.15-MariaDB-log Source distribution
MariaDB [(none)]> show variables like '%port';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| extra_port | 0 |
| innodb_deadlock_report | full |
| large_files_support | ON |
| port | 3308 |
| report_port | 3308 |
| require_secure_transport | OFF |
+--------------------------+-------+
6 rows in set (0.001 sec)
[root@centos7 ~]# mysql -S /mysqldb/3309/socket/mysql.sock
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.6.8-MariaDB Source distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show variables like '%port';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| extra_port | 0 |
| innodb_deadlock_report | full |
| large_files_support | ON |
| port | 3309 |
| report_port | 3309 |
| require_secure_transport | OFF |
+--------------------------+-------+
6 rows in set (0.001 sec)
# 停止实例
[root@centos7 ~]# /mysqldb/3307/bin/mysqld stop
2.5 设置root密码
[root@centos7 ~]# mysql -S /mysqldb/3308/socket/mysql.sock
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.6.8-MariaDB Source distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant all privileges on *.* to 'root'@'%' identified by '123456';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> grant all privileges on *.* to 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.002 sec)
MariaDB [(none)]> select user,host,password from mysql.user;
+-------------+-----------+-------------------------------------------+
| User | Host | Password |
+-------------+-----------+-------------------------------------------+
| mariadb.sys | localhost | |
| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| mysql | localhost | invalid |
| | localhost | |
| | server | |
| root | % | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-------------+-----------+-------------------------------------------+
6 rows in set (0.001 sec)
[root@centos7 ~]# mysql -S /mysqldb/3307/socket/mysql.sock -uroot -p'123456' # 指定密码登录