紀錄 mysql 操作
# login
mysql -u root
mysql -u foouser -p
# list DB
show databases;
# reset
/etc/init.d/mysql stop
mysqld_safe --skip-grant-tables &
mysql -u root
use mysql;
update user set password=password('123') where user='root' and host='localhost';
quit;
# 改回不用密碼登錄
mysqladmin -u root -p'oldpassword' password ''
# 改密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY 'P@ssw0rd';
## mysql 升級
/var/lib/mysql 蓋掉
有需要的話,重設 root 密碼
mysql_upgrade -u root -p
PHP 連線 mysql 須帶入 socket 參數
[root@node3 ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.26 Source distribution
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> status;
--------------
mysql Ver 8.0.26 for Linux on x86_64 (Source distribution)
Connection id: 8
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 8.0.26 Source distribution
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/lib/mysql/mysql.sock
Binary data as: Hexadecimal
Uptime: 1 min 16 sec
php