service mysql start //啓動mysql服務
service mysql stop //關閉mysql服務
sudo netstat -tap | grep mysql //檢視mysql節點listen狀態
mysql -u root -p //進入mysql shell介面
設定root使用者密碼
xt@xt-virtual-machine:~$ sudo cat /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = vtUHxfg5TyjolR2l
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = vtUHxfg5TyjolR2l
socket = /var/run/mysqld/mysqld.sock
xt@xt-virtual-machine:~$ mysql -u debian-sys-maint -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.31-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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; #連線到mysql數據庫
mysql> update mysql.user set authentication_string=password('123456') where user='root' and Host ='localhost'; #修改密碼123456是密碼
mysql> update user set plugin="mysql_native_password";
mysql> flush privileges;
mysql> quit;
service mysql restart
重置root密碼
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
skip-grant-tables
service mysql restart
常用操作
show databases //檢視所有數據庫,mysql數據庫用來新增使用者修改密碼
use mysql //開啓相關庫
show tables //檢視該庫中的所有表
describe //檢視錶結構