1.創建數據庫,帳號及授權
create database testdb;
CREATE USER 'rusking'@'%' IDENTIFIED BY '12345678';
CREATE USER 'rusking'@'%' IDENTIFIED WITH mysql_native_password BY '12345678';
GRANT ALL ON testdb.* TO 'rusking'@'%' WITH GRANT OPTION;
flush privileges;
2.登錄Mysql:
mysql -u db_user -pdb_password -h db_host db_name
mysql -urusking -p12345678 -h loclahost testdb
3.查看Mysql版本
[root@www ~]# mysql -V mysql Ver 8.0.15 for Linux on x86_64 (MySQL Community Server - GPL) [root@www ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 20 Server version: 8.0.15 MySQL Community Server - GPL Copyright (c) 2000, 2019, 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> select version(); +-----------+ | version() | +-----------+ | 8.0.15 | +-----------+ 1 row in set (0.01 sec) mysql> status; -------------- mysql Ver 8.0.15 for Linux on x86_64 (MySQL Community Server - GPL) Connection id: 20 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 8.0.15 MySQL Community Server - GPL 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 Uptime: 1 hour 5 min 14 sec
4. 查看及修改加密方式
select user,plugin from user ;
ALTER USER 'rusking'@'%' IDENTIFIED WITH mysql_native_password BY '12345678';
5. 導入數據庫:
常用source 命令
進入mysql數據庫控制台,
如mysql -u root -p
mysql>use 數據庫
然后使用source命令,后面參數為腳本文件(如這里用到的.sql)
mysql>source d:wcnc_db.sql
6.其它命令
show databases;--查看所有數據庫
use testdb;--切換到testdb數據庫
show tables;---查看當前庫中的所有表
select user(); --查看當前登錄用戶
select database();--查看當前連接的數據庫
describe tablename; --查看表結構
show status like '%connections'; --查看當前運行的Mysql所使用的跟connections相關的參數。
show status; --查看當前運行的Mysql所使用的所有參數
show variables like ‘%connections%'; --查看跟connections相關的所有變量
show variables ; --查看所有變量
show processlist; --查看當前數據庫正在處理的隊列
show full processlist;
這兩個命令的結果都是從information_schema.processlist表取的結果
=====MySQLTuner
這個工具會根據你的數據庫環境的配置給出一些修改建議。
What is MySQLTuner
MySQLTuner is a great little utility to tune up your MySQL instance to perform at it best.
Install MySQLTuner
#yum -y install mysqltuner
Run MySQLTuner
Simply type mysqltuner and get overwhelmed with a list of tweak suggestions.
#mysqltuner