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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

8.22 13.1-13.3

發布時間:2025/3/8 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 8.22 13.1-13.3 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

13.1 設置更改root密碼

?

Mysqlroot用戶為mysql的超級管理員用戶,類似linux下的root

也可以創建普通用戶連接mysql

默認mysqlroot密碼為空

?

操作:

檢查mysql服務是否啟動

[root@hyc-01-01 ~]# ps aux|grep mysql

root?????? 922? 0.0? 0.1 115432? 1476 ???????? S??? 821?? 0:00 /bin/sh /usr/local/mysql/binmysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/hyc-01-01.pid

mysql???? 1155? 0.0 44.7 1302728 451120 ?????? Sl?? 821?? 1:25 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=hyc-01-01.err --pid-file=/data/mysql/hyc-01-01.pid --socket=/tmp/mysql.sock

root????? 2607? 0.0? 0.0 112724?? 980 pts/1??? S+?? 20:31?? 0:00 grep --color=auto mysql

若未啟動則需要啟動:

[root@hyc-01-01 ~]# /etc/init.d/mysqld start

Mysql相關命令在/usr/local/mysql/bin路徑下,但該路徑不在環境變量PATH

[root@hyc-01-01 ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

所以執行mysql相關命令時會報錯提示命令未找到

為了能正常執行mysql的命令,需要將該路徑加入環境變量PATH

1

[root@hyc-01-01 ~]# export PATH=$PATH:/usr/local/mysql/bin/

[root@hyc-01-01 ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin/ 臨時生效(系統重啟后失效)

2 永久生效

[root@hyc-01-01 ~]# vim /etc/profile

??? fi

done

?

unset i

unset -f pathmunge

export PATH=$PATH:/usr/local/mysql/bin/

[root@hyc-01-01 ~]# source /etc/profile

執行profile文件(改寫/etc/profile后若不重新執行則改寫的內容不生效)

此時mysql相關命令執行正常

[root@hyc-01-01 ~]# mysql -uroot –p 指定使用root登錄mysql-p參數用于指定密碼

Enter password:

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

?

mysql> 此時已經登入mysql,用戶可以在這里操作mysql

mysql> quit quit登出mysql

Bye

首次設置root用戶密碼:

[root@hyc-01-01 ~]# mysqladmin -uroot password 'hyclinux.1'

Warning: Using a password on the command line interface can be insecure.

這里系統認為密碼明文顯示不安全,所以會出現提示,不是錯誤,可以不管

?

再次使用root用戶登入mysql

[root@hyc-01-01 ~]# mysql -uroot

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

未提供密碼登入操作被拒絕

?

再次修改root用戶密碼:

[root@hyc-01-01 ~]# mysqladmin -uroot -p'hyclinux.1' password 'hyc940421'

Warning: Using a password on the command line interface can be insecure.

注意:

需要使用-p參數輸入原來的密碼

-p參數后緊跟密碼,沒有空格

通常使用單引號使所有特殊字符去義

?

在不知道root密碼的情況下修改root密碼:

修改/etc/my.cnf配置文件:

[root@hyc-01-01 ~]# vim /etc/my.cnf

? 1 [mysqld]

? 2 skip-grant 忽略授權,即在用戶登錄mysql時不需要密碼

? 3 federated

? 4 datadir=/data/mysql

? 5 socket=/tmp/mysql.sock

重啟服務:

[root@hyc-01-01 ~]# /etc/init.d/mysqld restart

Shutting down MySQL.. SUCCESS!

Starting MySQL.. SUCCESS!

無需密碼直接登錄:

[root@hyc-01-01 ~]# mysql -uroot

Welcome to the MySQL monitor.? Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.39 MySQL Community Server (GPL)

?

Copyright (c) 2000, 2018, 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>

更改root密碼:

修改mysql中的mysql庫中的user表,這里記錄了用戶名、密碼、權限等信息

mysql> use mysql 切換到mysql

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

?

Database changed

mysql> select * from user; 查看mysql庫中的信息

mysql> select password from user;

+-------------------------------------------+

| password??????????????????????????? ??????|

+-------------------------------------------+

| *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

|???????????????? ??????????????????????????|

|?????????????????????????????????????????? |

+-------------------------------------------+

6 rows in set (0.00 sec)

user表中密碼信息是加密的字符串,這些加密的字符串由password函數生成,所以修改密碼時也需要password函數對密碼進行加密

mysql> update user set password=password('123456') where user='root';

設置root密碼為123456并使用password函數加密

Query OK, 4 rows affected (0.00 sec)

Rows matched: 4? Changed: 4? Warnings: 0 4行發生改變

?

刪除/etc/my.cnf中的skip-grant后重啟mysql服務測試:

[root@hyc-01-01 ~]# mysql -uroot -p

Enter password:? 這里輸入123456

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

?

mysql>

?

13.2 連接mysql

?

連接本機

[root@hyc-01-01 ~]# mysql -uroot -p

連接遠程

[root@hyc-01-01 ~]# mysql -uroot -p123456 -h127.0.0.1 -P3306

Socket連接(僅本機連接)

[root@hyc-01-01 ~]# mysql -uroot -p123456 -S/tmp/mysql.sock

連接后執行操作

[root@hyc-01-01 ~]# mysql -uroot -p123456 -e "show databases"

Warning: Using a password on the command line interface can be insecure.

+--------------------+

| Database?????????? |

+--------------------+

| information_schema |

| mysql????????????? |

| performance_schema |

| test?????????????? |

+--------------------+

?

13.3 mysql常用命令

?

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 -A

?

Database changed

?

查看數據庫中的表

mysql> show tables;

+---------------------------+

| Tables_in_mysql?????????? |

+---------------------------+

| columns_priv????????????? |

| db??????????????????????? |

| event???????????????????? |

| func????????????????????? |

| general_log?????????????? |

| help_category???????????? |

| help_keyword????????????? |

| help_relation???????????? |

| help_topic??????????????? |

| innodb_index_stats??????? |

| innodb_table_stats??????? |

| ndb_binlog_index????????? |

| plugin??????????????????? |

| proc????????????????????? |

| procs_priv??????????????? |

| proxies_priv????????????? |

| servers?????????????????? |

| slave_master_info???????? |

| slave_relay_log_info????? |

| slave_worker_info???????? |

| slow_log????????????????? |

| tables_priv?????????????? |

| time_zone???????????????? |

| time_zone_leap_second???? |

| time_zone_name??????????? |

| time_zone_transition????? |

| time_zone_transition_type |

| user????????????????????? |

+---------------------------+

28 rows in set (0.00 sec)

?

查看user表中包含的字段

mysql> desc user;

?

查看mysql數據庫中的user表是如何創建的

mysql> show create table user\G;

*************************** 1. row ***************************

?????? Table: user

Create Table: CREATE TABLE `user` (

? `Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '',

? `User` char(16) COLLATE utf8_bin NOT NULL DEFAULT '',

? `Password` char(41) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '',

? `Select_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Insert_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Update_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Delete_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Create_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Drop_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Reload_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Shutdown_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Process_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `File_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Grant_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `References_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Index_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Alter_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Show_db_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Super_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Create_tmp_table_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Lock_tables_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Execute_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Repl_slave_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Repl_client_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Create_view_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Show_view_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Create_routine_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Alter_routine_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Create_user_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Event_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Trigger_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `Create_tablespace_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? `ssl_type` enum('','ANY','X509','SPECIFIED') CHARACTER SET utf8 NOT NULL DEFAULT '',

? `ssl_cipher` blob NOT NULL,

? `x509_issuer` blob NOT NULL,

? `x509_subject` blob NOT NULL,

? `max_questions` int(11) unsigned NOT NULL DEFAULT '0',

? `max_updates` int(11) unsigned NOT NULL DEFAULT '0',

? `max_connections` int(11) unsigned NOT NULL DEFAULT '0',

? `max_user_connections` int(11) unsigned NOT NULL DEFAULT '0',

? `plugin` char(64) COLLATE utf8_bin DEFAULT 'mysql_native_password',

? `authentication_string` text COLLATE utf8_bin,

? `password_expired` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',

? PRIMARY KEY (`Host`,`User`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Users and global privileges'

1 row in set (0.00 sec)

?

ERROR:

No query specified

顯示的內容包括表的名稱、字段、每個字段的格式及其他參數,還有表的引擎、字符集和創建表使用的語句

如果不加/G顯示的內容會比較混亂

mysql> select * from user;

| Host????? | User | Password? ????????????????????????????????| Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin??????????????? | authentication_string | password_expired |

| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | Y?????????? | Y?????????? | Y?????????? | Y?????? ????| Y?????????? | Y???????? | Y?????????? | Y???????????? | Y??????????? | Y???????? | Y????????? | Y?????????????? | Y????????? | Y????????? | Y??????????? | Y????????? | Y???????????????????? | Y??????????????? | Y??????????? | Y?????????????? | Y???? ???????????| Y??????????????? | Y????????????? | Y?????????????????? | Y????????????????? | Y??????????????? | Y????????? | Y??????????? | Y????????????????????? |????????? |??????????? |???????????? |????????????? |???????????? 0 |?????????? 0 |????????? ?????0 |??????????????????? 0 | mysql_native_password |?????????????????????? | N??????????????? |

| hyc-01-01 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | Y?????????? | Y?????????? | Y?????????? | Y?????????? | Y?????????? | Y???????? | Y???????? ??| Y???????????? | Y??????????? | Y???????? | Y????????? | Y?????????????? | Y????????? | Y????????? | Y??????????? | Y????????? | Y???????????????????? | Y??????????????? | Y??????????? | Y?????????????? | Y??????????????? | Y??????????????? | Y???????? ?????| Y?????????????????? | Y????????????????? | Y??????????????? | Y????????? | Y??????????? | Y????????????????????? |????????? |??????????? |???????????? |????????????? |???????????? 0 |?????????? 0 |?????????????? 0 |??????????????????? 0 | mysql_native_password |?????????????????????? | N??????????????? |

| 127.0.0.1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | Y?????????? | Y?????????? | Y?????????? | Y?????????? | Y?????????? | Y???????? | Y?????????? | Y???????????? | Y??????????? | Y????? ???| Y????????? | Y?????????????? | Y????????? | Y????????? | Y??????????? | Y????????? | Y???????????????????? | Y??????????????? | Y??????????? | Y?????????????? | Y??????????????? | Y??????????????? | Y????????????? | Y?????????????????? | Y??????????? ??????| Y??????????????? | Y????????? | Y??????????? | Y????????????????????? |????????? |??????????? |???????????? |????????????? |???????????? 0 |?????????? 0 |?????????????? 0 |??????????????????? 0 | mysql_native_password |?????????????????????? | N?? ?????????????|

| ::1?????? | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | Y?????????? | Y?????????? | Y?????????? | Y?????????? | Y?????????? | Y???????? | Y?????????? | Y???????????? | Y??????????? | Y???????? | Y????????? | Y?????????????? | Y????????? | Y?????? ???| Y??????????? | Y????????? | Y???????????????????? | Y??????????????? | Y??????????? | Y?????????????? | Y??????????????? | Y??????????????? | Y????????????? | Y?????????????????? | Y????????????????? | Y??????????????? | Y????????? | Y??????????? | Y ?????????????????????|????????? |??????????? |???????????? |????????????? |???????????? 0 |?????????? 0 |?????????????? 0 |??????????????????? 0 | mysql_native_password |?????????????????????? | N??????????????? |

| localhost |????? |????????????????????? ?????????????????????| N?????????? | N??????????

?????????? 0 |?????????????? 0 |??????????????????? 0 | mysql_native_password | NULL????????????????? | N??????????????? |

6 rows in set (0.00 sec)

mysql> select * from user\G;

*************************** 1. row ***************************

????????????????? Host: localhost

??????????????? ??User: root

????????????? Password: *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9

?????????? Select_priv: Y

?????????? Insert_priv: Y

?????????? Update_priv: Y

?????????? Delete_priv: Y

?????????? Create_priv: Y

???????????? Drop_priv: Y

?????????? Reload_priv: Y

???????? Shutdown_priv: Y

????????? Process_priv: Y

???????????? File_priv: Y

??????????? Grant_priv: Y

?????? References_priv: Y

??????????? Index_priv: Y

??????????? Alter_priv: Y

????????? Show_db_priv: Y

??????????? Super_priv: Y

?Create_tmp_table_priv: Y

????? Lock_tables_priv: Y

????????? Execute_priv: Y

?authentication_string:

????? password_expired: N

*************************** 3. row ***************************

????????????????? Host: 127.0.0.1

????????????????? User: root

?????? ???????Password: *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9

?????????? Select_priv: Y

?????????? Insert_priv: Y

?????????? Update_priv: Y

?????????? Delete_priv: Y

?????????? Create_priv: Y

???????????? Drop_priv: Y

?????????? Reload_priv: Y

???????? Shutdown_priv: Y

????????? Process_priv: Y

???????????? File_priv: Y

??????????? Grant_priv: Y

?authentication_string:

????? password_expired: N

*************************** 4. row ***************************

????????????????? Host: ::1

????????????????? User: root

????????????? Password: *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9

?…

?????????? max_updates: 0

?????? max_connections: 0

? max_user_connections: 0

??????????????? plugin: mysql_native_password

?authentication_string:

????? password_expired: N

*************************** 5. row ***************************

????????????????? Host: localhost

????????????????? User:

????????????? Password:

???????????? File_priv: N

??????? ????Grant_priv: N

?????? References_priv: N

??????????? Index_priv: N

??????????? Alter_priv: N

????????? Show_db_priv: N

??????????? Super_priv: N

?Create_tmp_table_priv: N

????? Lock_tables_priv: N

????????? Execute_priv: N

?????????? max_updates: 0

?????? max_connections: 0

? max_user_connections: 0

??????????????? plugin: mysql_native_password

?authentication_string: NULL

????? password_expired: N

*************************** 6. row ***************************

????????????????? Host: hyc-01-01

????????????????? User:

????????????? Password:

?????????? Select_priv: N

?????????? Insert_priv: N

?????????? Update_priv: N

?????????? Delete_priv: N

?????????? Create_priv: N

????? Create_user_priv: N

??????????? Event_priv: N

????????? Trigger_priv: N

Create_tablespace_priv: N

????????????? ssl_type:

??????????? ssl_cipher:

?????????? x509_issuer:

????????? x509_subject:

???????? max_questions: 0

?????????? max_updates: 0

?????? max_connections: 0

? max_user_connections: 0

??????????????? plugin: mysql_native_password

?authentication_string: NULL

????? password_expired: N

6 rows in set (0.00 sec)

?

ERROR:

No query specified

?

查看當前用戶:

mysql> select user();

+----------------+

| user()???????? |

+----------------+

| root@localhost |

+----------------+

1 row in set (0.00 sec)

當前用戶為root,主機名為localhost(即本地)

登出后重新登錄:

通過127.0.0.1登錄,默認端口3306

[root@hyc-01-01 ~]# mysql -uroot -p123456 -h127.0.0.1

Warning: Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.? Commands end with ; or \g.

Your MySQL connection id is 10

Server version: 5.6.39 MySQL Community Server (GPL)

?

Copyright (c) 2000, 2018, 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 user();

+----------------+

| user()???????? |

+----------------+

| root@localhost |

+----------------+

1 row in set (0.00 sec)

登錄用戶為root,主機名localhost

?

[root@hyc-01-01 ~]# mysql -uroot -p123456 -h192.168.31.129

Warning: Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.? Commands end with ; or \g.

Your MySQL connection id is 11

Server version: 5.6.39 MySQL Community Server (GPL)

?

Copyright (c) 2000, 2018, 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 user();

+----------------+

| user()???????? |

+----------------+

| root@hyc-01-01 |

+----------------+

1 row in set (0.00 sec)

登錄用戶為root,主機名hyc-01-01

這里ip地址192.168.31.129被反解析到主機名hyc-01-01

?

Mysql中也可以記錄命令歷史,使用上下方向鍵可以查看歷史命令(類似linux

Mysql歷史命令記錄位置:

[root@hyc-01-01 ~]# ls -a|grep mysql_history

.mysql_history

[root@hyc-01-01 ~]# pwd

/root

?

Mysql也支持ctrl+L清屏

?

查看當前使用的數據庫:

mysql> select database();

+------------+

| database() |

+------------+

| NULL?????? |

+------------+

1 row in set (0.00 sec)

?

mysql> use 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 -A

?

Database changed

mysql> select database();

+------------+

| database() |

+------------+

| mysql????? |

+------------+

1 row in set (0.00 sec)

?

創建庫:

mysql> show databases;

+--------------------+

| Database?????????? |

+--------------------+

| information_schema |

| mysql????????????? |

| performance_schema |

| test?????????????? |

+--------------------+

4 rows in set (0.00 sec)

?

mysql> create database test1; 創建庫test1

Query OK, 1 row affected (0.00 sec)

?

mysql> show databases;

+--------------------+

| Database?????????? |

+--------------------+

| information_schema |

| mysql????????????? |

| performance_schema |

| test?????????????? |

| test1????????????? |

+--------------------+

5 rows in set (0.00 sec)

創建表:

mysql> use test1

Database changed

mysql> create table test1(`id` int(4), `name` char(40));

Query OK, 0 rows affected (0.04 sec)

在數據庫test1下創建表test1,表的字段包括id(數字形式,最長為4)和name(字符串形式,最長為40

mysql> show create table test1\G;

*************************** 1. row ***************************

?????? Table: test1

Create Table: CREATE TABLE `test1` (

? `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

使用了默認引擎InnoDB,默認字符集latin1

mysql> #create table test1(`id` int(4),`name` char(40)) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CHARSET指定字符集為utf-8

ENGINE指定數據庫引擎為InnoDB

?

刪除表:

mysql> drop table test1;

Query OK, 0 rows affected (0.03 sec)

?

重新創建表test1

mysql> create table test1(`id` int(4),`name` char(40)) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Query OK, 0 rows affected (0.03 sec)

?

mysql>? show create table test1\G;

*************************** 1. row ***************************

?????? Table: test1

Create Table: CREATE TABLE `test1` (

? `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

此時表使用的字符集為utf8

?

查看當前數據庫版本:

mysql> select version();

+-----------+

| version() |

+-----------+

| 5.6.39??? |

+-----------+

1 row in set (0.00 sec)

?

查看數據庫的狀態:

mysql> show status;

?

查看各種參數:

mysql> show variables;

這些參數均可以在my.cnf中定義

指定查看某個或某些參數:

mysql> show variables like 'max_connect%'; 查看匹配max_connect字段的參數(使用%表示通配)

+--------------------+-------+

| Variable_name????? | Value |

+--------------------+-------+

| max_connect_errors | 100?? |

| max_connections??? | 151?? |

+--------------------+-------+

2 rows in set (0.00 sec)

?

不加%則表示嚴格匹配

mysql> show variables like 'slow%';

+---------------------+--------------------------------+

| Variable_name?????? | Value????????????????????????? |

+---------------------+--------------------------------+

| slow_launch_time??? | 2????????????????????????????? |

| slow_query_log????? | OFF??????????????????????????? |

| slow_query_log_file | /data/mysql/hyc-01-01-slow.log |

+---------------------+--------------------------------+

3 rows in set (0.00 sec)

?

mysql> show variables like 'slow';

Empty set (0.00 sec)

?

修改參數:

1 可以修改配置文件 重啟生效,永久有效

[root@hyc-01-01 hyc]# vim /etc/my.cnf

2 命令行修改,使新的值在內存中生效 重啟失效

mysql> set global max_connect_errors=1000; 原來100

Query OK, 0 rows affected (0.00 sec)

?

查看隊列:

類似linux系統下用ps aux查看

mysql> show processlist;

+----+------+-----------+------+---------+------+-------+------------------+

| Id | User | Host????? | db?? | Command | Time | State | Info???????????? |

+----+------+-----------+------+---------+------+-------+------------------+

| 12 | root | localhost | NULL | Sleep?? | 3002 |?????? | NULL???????????? |

| 13 | root | localhost | NULL | Sleep?? | 2991 |?????? | NULL???????????? |

| 20 | root | localhost | NULL | Query?? |??? 0 | init? | show processlist |

+----+------+-----------+------+---------+------+-------+------------------+

3 rows in set (0.00 sec)

使用show processlist顯示的最后一列(info)可能不完整,使用show full processlist會顯示完整

mysql> show full processlist;

+----+------+-----------+------+---------+------+-------+-----------------------+

| Id | User | Host????? | db?? | Command | Time | State | Info????????????????? |

+----+------+-----------+------+---------+------+-------+-----------------------+

| 12 | root | localhost | NULL | Sleep?? | 3013 |?????? | NULL????????????????? |

| 13 | root | localhost | NULL | Sleep?? | 3002 |?????? | NULL????????????????? |

| 20 | root | localhost | NULL | Query?? |??? 0 | init? | show full processlist |

+----+------+-----------+------+---------+------+-------+-----------------------+

3 rows in set (0.00 sec)


轉載于:https://blog.51cto.com/12216458/2163143

總結

以上是生活随笔為你收集整理的8.22 13.1-13.3的全部內容,希望文章能夠幫你解決所遇到的問題。

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