mysql的设置更改root密码、连接、常用命令
生活随笔
收集整理的這篇文章主要介紹了
mysql的设置更改root密码、连接、常用命令
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
13.1 設置更改root密碼
- 更改環境變量PATH ,增加mysql絕對路徑
首次直接使用mysql會提示‘該命令不存在’,原因是還沒有將該命令加入環境變量,如果要使用該命令,需要使用其絕對路徑:/usr/local/mysql/bin/mysql,為了方便,先將其加入系統環境變量:
mysql命令路徑暫時加入環境變量,系統重啟后該變量會失效,若要永久生效,需要將其加入環境變量配置文件:
vi /etc/profile#在配置文件最后 把上面的命令加#執行source命令生效 [root@taoyuan ~]# source /etc/profile- 首次登陸
注: -p=passwd,使用密碼登錄,在此可以將密碼直接輸入在命令行(跟在-p后面,不加空格:-p'123456'<此處單引號可以不加,但是當密碼中有特殊符號時必須加,所以在命令行輸入密碼時養成習慣:加單引號>),也可以不在命令行輸入,只跟-p選項,然后根據提示信息:“Enter password”,輸入密碼進行登錄(此方法不會暴露用戶密碼,安全)。
- 設置mysql 的root密碼 && 更改
- 密碼重置
注: 完成該操作之后就可以任意登錄mysql了(無需密碼),所以此時mysql安全性很差,平時配置文件中一定不要添加該參數!!
13.2 連接mysql
- 本機直接登陸
- 通過端口連接(TCP/IP)
- 使用sock的連接
- 連接mysql操作一個命令
13.3 mysql常用命令
#查詢庫 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec)#切換庫 mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed#查看庫里的表 mysql> show tables;#查看字段 mysql> desc user;#查看建表語句 mysql> show create table user\G; #\G 表示:豎排顯示#查看當前用戶 mysql> select user(); +----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec)#查看當前使用的數據庫 mysql> select database(); +------------+ | database() | +------------+ | NULL | +------------+ 1 row in set (0.00 sec)mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed mysql> select database(); +------------+ | database() | +------------+ | mysql | +------------+ 1 row in set (0.00 sec)#創建庫 mysql> create database db1; Query OK, 1 row affected (0.00 sec)mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | db1 | | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.00 sec)#創建表 mysql> use db1; Database changed mysql> create table t1(`id` int(4), `name` char(40)); Query OK, 0 rows affected (0.02 sec)mysql> show create table t1\G; *************************** 1. row ***************************Table: t1 Create Table: CREATE TABLE `t1` (`id` int(4) DEFAULT NULL,`name` char(40) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec)ERROR: No query specified #ENGINE=InnoDB DEFAULT CHARSET=latin1 可以自定義 #如下 mysql> drop table t1; #刪除t1表 Query OK, 0 rows affected (0.01 sec) mysql> create table t1(`id` int(4), `name` char(40)) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.01 sec)mysql> show create table t1\G; *************************** 1. row ***************************Table: t1 Create Table: CREATE TABLE `t1` (`id` int(4) DEFAULT NULL,`name` char(40) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 1 row in set (0.00 sec)ERROR: No query specified#查看當前數據庫版本 mysql> select version(); +-----------+ | version() | +-----------+ | 5.6.35 | +-----------+ 1 row in set (0.00 sec)#查看數據庫狀態 mysql> show status;#查看各參數 mysql> show variables #指定的參數 mysql> show variables like 'max_connect%'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | max_connect_errors | 100 | | max_connections | 151 | +--------------------+-------+ 2 rows in set (0.00 sec)#修改參數 mysql> set global max_connect_errors=1000; Query OK, 0 rows affected (0.00 sec) #只在內存中生效#查看隊列 mysql> show processlist; +----+------+-----------+------+---------+------+-------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+------+---------+------+-------+------------------+ | 9 | root | localhost | db1 | Query | 0 | init | show processlist | +----+------+-----------+------+---------+------+-------+------------------+ 1 row in set (0.00 sec)mysql> show full processlist; +----+------+-----------+------+---------+------+-------+-----------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+------+---------+------+-------+-----------------------+ | 9 | root | localhost | db1 | Query | 0 | init | show full processlist | +----+------+-----------+------+---------+------+-------+-----------------------+ 1 row in set (0.00 sec) #full 查看完整的隊列小常識:
敲過的命令歷史在mysql_history 文件里
轉載于:https://blog.51cto.com/3622288/2060499
總結
以上是生活随笔為你收集整理的mysql的设置更改root密码、连接、常用命令的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vba操作IE浏览器
- 下一篇: 猎头,希望您能更理解找工作的人