博客地址:http://www.moonxy.comphp
1、前言mysql
前面幾章介紹了 MySQL 的安裝和簡單的配置,只會這些還不夠,做爲 Linux 系統管理員,咱們還須要掌握一些基本的操做,以知足平常管理工做所需。MySQL環境中的命令須要帶一個分號做爲命令結束符。linux
MySQL 之父 Widenius 先生離開了 Sun 以後,以爲依靠 Sun/Oracle 來發展 MySQL,實在很不靠譜,因而決定另開分支,這個分支的名字叫作 MariaDB。MariaDB 跟 MySQL 在絕大多數方面是兼容的,對於開發者來講,幾乎感受不到任何不一樣。目前 MariaDB 是發展最快的 MySQL 分支版本,新版本發佈速度已經超過了 Oracle 官方的 MySQL 版本。web
2、經常使用操做sql
2.1 增長新用戶和受權shell
鏈接 MySQL 數據庫的命令爲:數據庫
[root@ryan linux]# mysql -h192.168.1.121 -uroot -p123456 -D mysql mysql: [Warning] Using a password on the command line interface can be insecure. Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 19 Server version: 5.7.22 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 database(); +------------+ | database() | +------------+ | mysql | +------------+ 1 row in set (0.00 sec)
-h 指定遠程MySQL數據庫服務器地址,-u 指定登陸用戶名,-p指定密碼,-D指定要直接鏈接到哪一個數據庫,默認鏈接端口爲 3306,也可使用 -P 選項來指定其餘端口。apache
也可使用 socket 登陸,以下:vim
[root@ryan linux]# mysql -uroot -S /tmp/mysql.sock -p123456
增長一個用戶 test1 密碼爲 123456,讓他能夠從任何主機上登陸,並對全部數據庫有查詢、插入、修改、刪除的權限。windows
首先用以root用戶連入MySQL,而後鍵入如下命令:
[root@ryan linux]# mysql -uroot -p123456 mysql: [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 13 Server version: 5.7.22 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> grant select,insert,update,delete on *.* to 'test1'@'%' identified by '123456'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye [root@ryan linux]# mysql -utest1 -p123456 mysql: [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 14 Server version: 5.7.22 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 用戶能夠從任何主機上登陸,並對全部數據庫有全部權限,以下:
[root@ryan linux]# mysql -uroot -p123456 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.22 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> grant all on *.* to 'root'@'%' identified by '123456'; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)
讓用戶 rain 從指定客戶端地址 192.168.1.101 訪問 MySQL 數據庫,並對全部數據庫有全部權限,以下:
mysql> grant all on discuz.* to 'rain'@'192.168.1.101' identified by '123456'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
其中,all 表示全部的權限(包括讀、寫、查詢、刪除等操做);discuz表示數據庫,*表示全部的表,若是是*.*則表示全部的數據庫和全部的表;identified by 後面跟密碼,用單引號括起來;用戶和主機的IP之間有一個符號 '@',命令中的 IP 也可使用 '%' 代替,表示全部主機。
受權先後對比,客戶端 windows 地址爲 192.168.1.101,MySQL 服務器端 Linux 地址爲 192.168.1.121,以下:
C:\Users\Administrator>mysql -urain -h192.168.1.121 -p123456 mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1045 (28000): Access denied for user 'rain'@'192.168.1.101' (using password: YES) C:\Users\Administrator>mysql -urain -h192.168.1.121 -p123456 mysql: [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.7.22 MySQL Community Server (GPL) Copyright (c) 2000, 2015, 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 respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
遠程鏈接 MySQL 服務器時,須要確保放行 3306 端口,以下:
[root@ryan linux]# iptables -I INPUT -p tcp --dport 3306 -j ACCEPT [root@ryan linux]# /etc/init.d/iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
也能夠直接修改 iptables 配置文件 /etc/sysconfig/iptables,添加3306放行規則,以下:
[root@ryan linux]# vim /etc/sysconfig/iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT [root@ryan linux]# service iptables restart
常見錯誤:
錯誤1:
# mysql -uroot -h192.168.1.121 -p
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.121' (10060)
出現這個錯誤的緣由多是:遠程3306端口未對外開放。
錯誤2:
[root@ryan linux]# mysql -uroot -h192.168.1.121 -p123456
ERROR 1130 (HY000): Host 'xxx' is not allowed to connect to this MySQL server
出現這個錯誤的緣由多是:此帳號不容許遠程登陸192.168.1.121 MySQL 數據庫主機。
錯誤3:
[root@ryan linux]# mysql -urain -h192.168.1.121 -p123456
ERROR 1045 (28000): Access denied for user 'rain'@'192.168.1.121' (using password: YES)
出現這個錯誤的緣由多是:密碼錯誤。
2.2 經常使用基本操做
查看有哪些數據庫
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | discuz | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec)
MySQL 中使用 Linux 命令
mysql> system pwd /root/linux
MySQL 查詢某個庫的表
Database changed 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 | | engine_cost | | event | | func | | general_log | | gtid_executed | | help_category | | help_keyword | | help_relation | | help_topic | | innodb_index_stats | | innodb_table_stats | | ndb_binlog_index | | plugin | | proc | | procs_priv | | proxies_priv | | server_cost | | 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 | +---------------------------+ 31 rows in set (0.00 sec)
查詢某個表的所有字段
mysql> desc user; +------------------------+-----------------------------------+------+-----+-----------------------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------------+-----------------------------------+------+-----+-----------------------+-------+ | Host | char(60) | NO | PRI | | | | User | char(32) | NO | PRI | | | | Select_priv | enum('N','Y') | NO | | N | | | Insert_priv | enum('N','Y') | NO | | N | | | Update_priv | enum('N','Y') | NO | | N | | | Delete_priv | enum('N','Y') | NO | | N | | | Create_priv | enum('N','Y') | NO | | N | | | Drop_priv | enum('N','Y') | NO | | N | | | Reload_priv | enum('N','Y') | NO | | N | | | Shutdown_priv | enum('N','Y') | NO | | N | | | Process_priv | enum('N','Y') | NO | | N | | | File_priv | enum('N','Y') | NO | | N | | | Grant_priv | enum('N','Y') | NO | | N | | | References_priv | enum('N','Y') | NO | | N | | | Index_priv | enum('N','Y') | NO | | N | | | Alter_priv | enum('N','Y') | NO | | N | | | Show_db_priv | enum('N','Y') | NO | | N | | | Super_priv | enum('N','Y') | NO | | N | | | Create_tmp_table_priv | enum('N','Y') | NO | | N | | | Lock_tables_priv | enum('N','Y') | NO | | N | | | Execute_priv | enum('N','Y') | NO | | N | | | Repl_slave_priv | enum('N','Y') | NO | | N | | | Repl_client_priv | enum('N','Y') | NO | | N | | | Create_view_priv | enum('N','Y') | NO | | N | | | Show_view_priv | enum('N','Y') | NO | | N | | | Create_routine_priv | enum('N','Y') | NO | | N | | | Alter_routine_priv | enum('N','Y') | NO | | N | | | Create_user_priv | enum('N','Y') | NO | | N | | | Event_priv | enum('N','Y') | NO | | N | | | Trigger_priv | enum('N','Y') | NO | | N | | | Create_tablespace_priv | enum('N','Y') | NO | | N | | | ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | | | ssl_cipher | blob | NO | | NULL | | | x509_issuer | blob | NO | | NULL | | | x509_subject | blob | NO | | NULL | | | max_questions | int(11) unsigned | NO | | 0 | | | max_updates | int(11) unsigned | NO | | 0 | | | max_connections | int(11) unsigned | NO | | 0 | | | max_user_connections | int(11) unsigned | NO | | 0 | | | plugin | char(64) | NO | | mysql_native_password | | | authentication_string | text | YES | | NULL | | | password_expired | enum('N','Y') | NO | | N | | | password_last_changed | timestamp | YES | | NULL | | | password_lifetime | smallint(5) unsigned | YES | | NULL | | | account_locked | enum('N','Y') | NO | | N | | +------------------------+-----------------------------------+------+-----+-----------------------+-------+ 45 rows in set (0.00 sec)
還能夠顯示的更加詳細,並且還能夠把建表語句列出來:
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(32) COLLATE utf8_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 NOT NULL DEFAULT 'mysql_native_password', `authentication_string` text COLLATE utf8_bin, `password_expired` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N', `password_last_changed` timestamp NULL DEFAULT NULL, `password_lifetime` smallint(5) unsigned DEFAULT NULL, `account_locked` 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)
能夠看到系統user表的主鍵爲 Host 和 User 組合主鍵。其中 \G 表示規範化顯示結果。
查看當前是哪一個用戶
mysql> select user(); +----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec)
查看當前所使用的數據庫
mysql> select database(); +------------+ | database() | +------------+ | mysql | +------------+ 1 row in set (0.00 sec)
建立一個新數據庫
mysql> create database db1; Query OK, 1 row affected (0.01 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | db1 | | discuz | | mysql | | performance_schema | | sys | +--------------------+ 6 rows in set (0.00 sec)
建立一個新表
mysql> use db1; Database changed mysql> create table client ('id' int(8), 'name' char(40)); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''id' int(8), 'name' char(40))' at line 1 mysql> create table client (`id` int(8), `name` char(40)); Query OK, 0 rows affected (0.34 sec)
使用命令行模式建立表時,字段先後加反引號,而不能加單引號。
查看當前MySQL數據庫版本
mysql> select version(); +-----------+ | version() | +-----------+ | 5.7.22 | +-----------+ 1 row in set (0.00 sec)
查看MySQL的當前狀態
mysql> show status; +-----------------------------------------------+--------------------------------------------------+ | Variable_name | Value | +-----------------------------------------------+--------------------------------------------------+ | Aborted_clients | 0 | | Aborted_connects | 10 | | Binlog_cache_disk_use | 0 | | Binlog_cache_use | 0 | | Binlog_stmt_cache_disk_use | 0 | | Binlog_stmt_cache_use | 0 | | Bytes_received | 10082 |
結果太多,此處只列出一部分。
查看MySQL的參數
mysql> show variables;system head +----------------------------------------------------------+-----------------------------+ | Variable_name | Value | +----------------------------------------------------------+-----------------------------+ | auto_increment_increment | 1 | | auto_increment_offset | 1 | | autocommit | ON | | automatic_sp_privileges | ON | | avoid_temporal_upgrade | OFF | | back_log | 80 | | basedir | /usr/local/mysql/
參數太多,此處只列出一部分,其中有許多參數能夠在 /etc/my.cnf 中定義。
修改 MySQL 的參數
mysql> show variables like 'max_connect%'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | max_connect_errors | 100 | | max_connections | 151 | +--------------------+-------+ 2 rows in set (0.01 sec) mysql> set global max_connect_errors=200; Query OK, 0 rows affected (0.00 sec) mysql> show variables like 'max_connect%'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | max_connect_errors | 200 | | max_connections | 151 | +--------------------+-------+ 2 rows in set (0.01 sec)
在 MySQL 命令行中,符號 "%" 相似於 shell 下的 "*",表示萬能匹配。使用命令 "set global" 能夠臨時修改某些參數,可是重啓MySQL服務後這些修改會失效。因此,若是你想讓這些修改恆久生效,就要在配置文件 /etc/my.cnf 中定義。
查看當前 MySQL 服務器的隊列
查看服務器隊列在平常的管理中比較頻繁,能夠經過它知道當前 MySQL 在幹什麼,也能夠發現是否有鎖表。
mysql> show processlist; +----+------+---------------------+--------------------+---------+-------+----------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+---------------------+--------------------+---------+-------+----------+------------------+ | 12 | root | 192.168.1.101:56915 | mysql | Sleep | 18357 | | NULL | | 26 | root | localhost | db1 | Query | 0 | starting | show processlist | | 27 | root | 192.168.1.101:64738 | NULL | Sleep | 2305 | | NULL | | 28 | root | 192.168.1.101:64742 | discuz | Sleep | 2316 | | NULL | | 29 | root | 192.168.1.101:64746 | information_schema | Sleep | 2298 | | NULL | +----+------+---------------------+--------------------+---------+-------+----------+------------------+ 5 rows in set (0.00 sec)
2.3 經常使用的 SQL 語句
插入一行
mysql> insert into client('id','name') values(1001,'Bob'); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''id','name') values(1001,'Bob')' at line 1 mysql> insert into client(`id`,`name`) values(1001,'Bob'); Query OK, 1 row affected (0.00 sec)
能夠看到字段名稱依然須要使用反引號包裹。
查詢語句
mysql> select * from client; +------+------+ | id | name | +------+------+ | 1001 | Bob | | 1002 | Adam | | 1003 | Deft | | 1004 | eft | +------+------+ 4 rows in set (0.00 sec) mysql> select name from client; +------+ | name | +------+ | Bob | | Adam | | Deft | | eft | +------+ 4 rows in set (0.00 sec)
更新數據
mysql> update client set name='Deft' where id=1004; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0
刪除數據
mysql> delete from client where id=1003; Query OK, 1 row affected (0.01 sec) mysql> select * from client; +------+------+ | id | name | +------+------+ | 1001 | Bob | | 1002 | Adam | | 1004 | Deft | +------+------+ 3 rows in set (0.00 sec)
清空某個表的數據
mysql> truncate table client;
刪除表結構
mysql> drop table client;
刪除數據庫
mysql> drop database db1;
2.4 MySQL 數據庫的備份和恢復
MySQL 數據庫備份
[root@ryan linux]# mysqldump -uroot -p123456 db1 > /tmp/mysql_db1_20180805.sql [root@ryan linux]# ll /tmp/mysql_db1_20180805.sql -rw-r--r-- 1 root root 1866 Aug 5 11:48 /tmp/mysql_db1_20180805.sql
MySQL 數據庫恢復
[root@ryan linux]# mysql -uroot -p123456 db1 < /tmp/mysql_db1_20180805.sql
上面的 db1 爲須要備份和恢復的數據庫名稱,/tmp/mysql_db1_20180805.sql備份的 sql 文件或者要恢復 sql 文件,這個文件中既包含建表語句,也包含表中數據,若是隻想保存建表語句,則添加 -d 選項。也能夠在備份或者恢復的時候指定字符集,使用 --default-character-set=utf8。若是隻想備份單個表,能夠在數據庫名後面添加表名,表示只備份指定表。
經常使用設置
關閉 MySQL 的 DNS 反查功能
在 my.cnf 中添加 skip-name-resolve,以下:
[root@ryan ~]# vim /etc/my.cnf
skip-name-resolve
當服務器放在局域網內進行測試時,數據庫的訪問速度仍是很快。但當服務器放到外網後,數據庫的訪問速度就變得很是慢。無論遠程鏈接 MySQL 的方式是通過 hosts 或是 IP 的模式,他都會對 DNS 作反查。mysqld 會嘗試去反查 IP -> dns ,因爲反查解析過慢,就會沒法應付過量的查詢。禁用 DNS 反向解析,就能大大加快 MySQL 鏈接的速度。不過,這樣的話就不能在 MySQL 的受權表中使用主機名了而只能用 IP 格式。
查看當前存儲引擎
mysql> show variables like '%engine%'; +----------------------------------+--------+ | Variable_name | Value | +----------------------------------+--------+ | default_storage_engine | InnoDB | | default_tmp_storage_engine | InnoDB | | disabled_storage_engines | | | internal_tmp_disk_storage_engine | InnoDB | +----------------------------------+--------+ 4 rows in set (0.01 sec) ##查看系統支持的引擎 mysql> show engines; +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES | | CSV | YES | CSV storage engine | NO | NO | NO | | MyISAM | YES | MyISAM storage engine | NO | NO | NO | | BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO | | PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO | | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO | | ARCHIVE | YES | Archive storage engine | NO | NO | NO | | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO | | FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ 9 rows in set (0.00 sec)
skip-innodb 參數表示忽略 innodb 存儲引擎(即便其不可用)。
添加該參數以後,/data/mysql/ 目錄下將不會出現 ibdata一、ib_logfile0 和 ib_logfile1 文件。ib_logfile 會記錄系統的回滾,重作日誌。當系統崩潰重啓時,用做事務重作;在系統正常時,每次 checkpoint 時間點,會將以前寫入事務應用到數據文件中。
配置慢查詢日誌
#log_show _queries = /path/to/slow_queries
#long_query_time = 1
3、安裝 phpMyAdmin
phpMyAdmin 是以 web 頁面的形式來管理 mysql 數據庫,目前好多建站程序包中都帶了 phpMyAdmin。下面咱們看一下如何手動自行安裝 phpMyAdmin。官網地址爲:https://www.phpmyadmin.net
能夠直接在首頁下載支持全部語言的版本:
或者進入下載頁面自行選擇版本:https://www.phpmyadmin.net/downloads/
下載
[root@ryan src]# wget https://files.phpmyadmin.net/phpMyAdmin/4.8.2/phpMyAdmin-4.8.2-all-languages.zip
解壓到指定目錄
[root@ryan src]# unzip /ucr/local/src/phpMyAdmin-4.8.2-all-languages.zip -d /data/www/DiscuzX
複製配置文件
因爲目錄較長,最好先重命名一下:mv /data/www/phpMyAdmin/phpMyAdmin-4.8.2-all-languages /data/www/phpMyAdmin/phpMyAdmin
[root@ryan ~]# cd /data/www/DiscuzX/phpMyAdmin [root@ryan phpMyAdmin]# cp config.sample.inc.php config.inc.php [root@ryan phpMyAdmin]# vim config.inc.php $cfg['blowfish_secret'] = 'ryan';#找到這一行,添加任意的值
保存退出。phpMyAdmin 的配置文件爲:config.inc.php
啓動 apache
[root@ryan phpMyAdmin]# apachectl -t
Syntax OK
[root@ryan phpMyAdmin]# apachectl start
訪問管理頁面
能夠看出多國語言版支持的語言種類不少,能夠根據本身須要選擇,以下:
輸入用戶名和密碼便可進入phpMyAdmin 管理後臺。
附錄