日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql的设置更改root密码、连接、常用命令

發布時間:2024/5/15 数据库 74 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql的设置更改root密码、连接、常用命令 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

13.1 設置更改root密碼

  • 更改環境變量PATH ,增加mysql絕對路徑
    首次直接使用mysql會提示‘該命令不存在’,原因是還沒有將該命令加入環境變量,如果要使用該命令,需要使用其絕對路徑:/usr/local/mysql/bin/mysql,為了方便,先將其加入系統環境變量:
[root@taoyuan ~]# export PATH=$PATH:/usr/local/mysql/bin/

mysql命令路徑暫時加入環境變量,系統重啟后該變量會失效,若要永久生效,需要將其加入環境變量配置文件:

vi /etc/profile#在配置文件最后 把上面的命令加#執行source命令生效 [root@taoyuan ~]# source /etc/profile
  • 首次登陸
[root@taoyuan ~]# mysql -uroot

注: -p=passwd,使用密碼登錄,在此可以將密碼直接輸入在命令行(跟在-p后面,不加空格:-p'123456'<此處單引號可以不加,但是當密碼中有特殊符號時必須加,所以在命令行輸入密碼時養成習慣:加單引號>),也可以不在命令行輸入,只跟-p選項,然后根據提示信息:“Enter password”,輸入密碼進行登錄(此方法不會暴露用戶密碼,安全)。

  • 設置mysql 的root密碼 && 更改
[root@taoyuan ~]# mysqladmin -uroot password '123456' Warning: Using a password on the command line interface can be insecure.[root@taoyuan ~]# mysql -uroot -p Enter password: #輸入密碼#更改新的密碼 [root@taoyuan ~]# mysqladmin -uroot -p'123456' password 'taoyuan' Warning: Using a password on the command line interface can be insecure. [root@taoyuan ~]# mysql -uroot -p'taoyuan' Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g.
  • 密碼重置
[root@taoyuan ~]# vi /etc/my.cnf#my.cnf 配置文件內容 [mysqld] skip-grant datadir=/data/mysql #增加skip-grant #忽略授權,意思是不用密碼登陸#重啟mysql服務 [root@taoyuan ~]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS! #登陸mysql 修改一個表 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 * from user;#查看user表 mysql> select password from user; +-------------------------------------------+ | password | +-------------------------------------------+ | *758ABA8398EF87C993D2C4420DACD8946907C873 | | | | | | | | | | | +-------------------------------------------+ 6 rows in set (0.00 sec)#修改密碼 mysql> update user set password=password('Aa123456') where user='root'; Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0#quit ,把/etc/my.cnf 配置文件修改回去 ,重啟mysql服務 [root@taoyuan ~]# vi /etc/my.cnf [root@taoyuan ~]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS! [root@taoyuan ~]# mysql -uroot -p'Aa123456' Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g.

注: 完成該操作之后就可以任意登錄mysql了(無需密碼),所以此時mysql安全性很差,平時配置文件中一定不要添加該參數!!

13.2 連接mysql

  • 本機直接登陸
[root@taoyuan ~]# mysql -uroot -pAa123456
  • 通過端口連接(TCP/IP)
[root@taoyuan ~]# mysql -uroot -pAa123456 -h127.0.0.1 -P3306 # -P 指定端口
  • 使用sock的連接
[root@taoyuan ~]# mysql -uroot -pAa123456 -S/tmp/mysql.sock #適用于本機連接
  • 連接mysql操作一個命令
[root@taoyuan ~]# mysql -uroot -pAa123456 -e "show databases" Warning: Using a password on the command line interface can be insecure. +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ #shell腳本使用中比較方便,可以直接獲取數據

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密码、连接、常用命令的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。