mysql [options] [database]
# 这三种方式都是可以的 shell> mysql -u root shell> mysql -uroot shell> mysql -user=root
[client] user=root password=000000 port = 3306 socket = /tmp/mysql.sock default-character-set = utf8mb4
zj@bogon:~$ mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 19 ...
shell> mysql -h 192.168.10.10 -P 3306 -uroot -p
--default-character-set=charset-name
shell> mysql -u user -default-character-set=charset
set names charset;
-e, --execute=name // 执行 sql 语句并退出
zj@bogon:~$ mysql mysql -e "select user,host from user" +-----------+-----------+ | user | host | +-----------+-----------+ | root | 127.0.0.1 | | mysql.sys | localhost | | root | localhost | +-----------+-----------+
shell> mysqladmin [options] command [command-options]...
create databasename Create a new database 新建数据库 debug Instruct server to write debug information to log 把 debug 日志记录到日志文件中 drop databasename Delete a database and all its tables 删除数据库 extended-status Gives an extended status message from the server 查看 MySQL 服务器的状态信息 flush-hosts Flush all cached hosts flush-logs Flush all logs flush-status Clear status variables flush-tables Flush all tables flush-threads Flush the thread cache flush-privileges Reload grant tables (same as reload) kill id,id,... Kill mysql threads password [new-password] Change old password to new-password in current format ping Check if mysqld is alive processlist Show list of active threads in server reload Reload grant tables refresh Flush all tables and close and open logfiles shutdown Take server down status Gives a short status message from the server start-slave Start slave stop-slave Stop slave variables Prints variables available version Get version info from server
zj@bogon:/usr/local/mysql/bin$ mysqladmin -uroot -p shutdown Enter password:
shell> mysqlbinlog [option] log-file1 log-file2...
MySQL [(none)]> reset master; Query OK, 0 rows affected (0.01 sec) MySQL [(none)]> create table t1(id int,name varchar); ERROR 1046 (3D000): No database selected MySQL [(none)]> reset master; Query OK, 0 rows affected (0.01 sec) MySQL [(none)]> create database t1; Query OK, 1 row affected (0.04 sec) MySQL [(none)]> create database t2; Query OK, 1 row affected (0.02 sec) MySQL [(none)]> use t1; Database changed MySQL [t1]> create table test1(id int, name varchar(30)); Query OK, 0 rows affected (0.11 sec) MySQL [t1]> insert into test1 value (1,'zj'); Query OK, 1 row affected (0.14 sec) MySQL [t1]> insert into test1 value (2,'zj2'); Query OK, 1 row affected (0.02 sec) MySQL [t1]> use t2; Database changed MySQL [t2]> create table test2(id int,name varchar(30)); Query OK, 0 rows affected (0.02 sec) MySQL [t2]> insert into test2 select * from t1.test1; Query OK, 2 rows affected (0.03 sec) Records: 2 Duplicates: 0 Warnings: 0 MySQL [t2]> select * from t1.test1; +------+------+ | id | name | +------+------+ | 1 | zj | | 2 | zj2 | +------+------+ 2 rows in set (0.02 sec) MySQL [t2]> select * from test2; +------+------+ | id | name | +------+------+ | 1 | zj | | 2 | zj2 | +------+------+ 2 rows in set (0.00 sec)
zj@bogon:/usr/local/mysql/bin$ sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 [sudo] password for zj: /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; # at 4 #170920 20:44:49 server id 1 end_log_pos 123 CRC32 0x42fd5a4d Start: binlog v 4, server v 5.7.18-log created 170920 20:44:49 at startup ...... create table test2(id int,name varchar(30)) /*!*/; # at 1366 #170920 20:50:29 server id 1 end_log_pos 1431 CRC32 0x18a95938 Anonymous_GTID last_committed=6 sequence_number=7 SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/; # at 1431 #170920 20:50:29 server id 1 end_log_pos 1509 CRC32 0x2fa8bd6c Query thread_id=4 exec_time=0 error_code=0 SET TIMESTAMP=1505911829/*!*/; BEGIN /*!*/; # at 1509 #170920 20:50:29 server id 1 end_log_pos 1622 CRC32 0x77ce6f3b Query thread_id=4 exec_time=0 error_code=0 SET TIMESTAMP=1505911829/*!*/; insert into test2 select * from t1.test1 /*!*/; # at 1622 #170920 20:50:29 server id 1 end_log_pos 1653 CRC32 0x41b7a45b Xid = 29 COMMIT/*!*/; SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/; DELIMITER ; # End of log file /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
zj@bogon:/usr/local/mysql/bin$ sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 -d t2 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; ...... SET TIMESTAMP=1505911829/*!*/; insert into test2 select * from t1.test1 /*!*/; # at 1622 #170920 20:50:29 server id 1 end_log_pos 1653 CRC32 0x41b7a45b Xid = 29 COMMIT/*!*/; SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/; DELIMITER ; # End of log file /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
zj@bogon:/usr/local/mysql/bin$ sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 -o 20 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; # at 4 #170920 20:44:49 server id 1 end_log_pos 123 CRC32 0x42fd5a4d Start: binlog v 4, server v 5.7.18-log created 170920 20:44:49 at startup # Warning: this binlog is either in use or was not closed properly. ROLLBACK/*!*/; BINLOG ' wWLCWQ8BAAAAdwAAAHsAAAABAAQANS43LjE4LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAADBYsJZEzgNAAgAEgAEBAQEEgAAXwAEGggAAAAICAgCAAAACgoKKioAEjQA AU1a/UI= '/*!*/; # at 1509 #170920 20:50:29 server id 1 end_log_pos 1622 CRC32 0x77ce6f3b Query thread_id=4 exec_time=0 error_code=0 use `t2`/*!*/; SET TIMESTAMP=1505911829/*!*/; SET @@session.pseudo_thread_id=4/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; SET @@session.sql_mode=1436549152/*!*/; SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; /*!\C utf8mb4 *//*!*/; SET @@session.character_set_client=45,@@session.collation_connection=45,@@session.collation_server=45/*!*/; SET @@session.lc_time_names=0/*!*/; SET @@session.collation_database=DEFAULT/*!*/; insert into test2 select * from t1.test1 /*!*/; # at 1622 #170920 20:50:29 server id 1 end_log_pos 1653 CRC32 0x41b7a45b Xid = 29 COMMIT/*!*/; SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/; DELIMITER ; # End of log file /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
zj@bogon:/usr/local/mysql/bin$ sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 -o 20 -r ./logfile zj@bogon:/usr/local/mysql/bin$ sudo more ./logfile /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; ...
zj@bogon:/usr/local/mysql/bin$ sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 -o 20 -s /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; ROLLBACK/*!*/; use `t2`/*!*/; SET TIMESTAMP=1505911829/*!*/; SET @@session.pseudo_thread_id=999999999/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; SET @@session.sql_mode=1436549152/*!*/; SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; /*!\C utf8mb4 *//*!*/; SET @@session.character_set_client=45,@@session.collation_connection=45,@@session.collation_server=45/*!*/; SET @@session.lc_time_names=0/*!*/; SET @@session.collation_database=DEFAULT/*!*/; insert into test2 select * from t1.test1 /*!*/; COMMIT/*!*/; SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/; DELIMITER ; # End of log file /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
zj@bogon:/usr/local/mysql/bin$ sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 --start-datetime="2017/09/30 05:00:00" --stop-datetime='2017/09/30 05:01:00'
sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 --start-position=4 --stop-datetime=100
shell> mysqlcheck [options] db_name [tables] shell> mysqlcheck [options] --database DB1 [DB2 DB3...] shell> mysqlcheck [options] --all-databse
zj@bogon:/data/mysql$ mysqlcheck -c t2 t2.test1 OK t2.test2 OK
zj@bogon:/data/mysql$ mysqlcheck -r t2 t2.test1 note : The storage engine for the table doesn't support repair t2.test2 OK
zj@bogon:/data/mysql$ mysqlcheck -a t2 t2.test1 OK t2.test2 OK
zj@bogon:/data/mysql$ mysqlcheck -o t2 t2.test1 note : Table does not support optimize, doing recreate + analyze instead status : OK t2.test2
mysqldump [OPTIONS] database [tables] // 备份单个数据库或者库中部分数据表 mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...] //备份指定的一个或者多个数据库 mysqldump [OPTIONS] --all-databases [OPTIONS] // 备份所有数据库
shell> mysqldump -h192.18.10.10 -p3306 -uroot -p test > test.sql
root@bogon:/usr/local/mysql/bin# ./mysqldump --compact t2 emp > emp.sql root@bogon:/usr/local/mysql/bin# more emp.sql /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `emp` ( `id` int(11) NOT NULL DEFAULT '0', `name` varchar(10) DEFAULT NULL, `context` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; INSERT INTO `emp` VALUES (1,'a','a'),(2,'b','b');
root@bogon:/usr/local/mysql/bin# ./mysqldump -c --compact t2 emp > emp.sql root@bogon:/usr/local/mysql/bin# more emp.sql /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `emp` ( `id` int(11) NOT NULL DEFAULT '0', `name` varchar(10) DEFAULT NULL, `context` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; INSERT INTO `emp` (`id`, `name`, `context`) VALUES (1,'a','a'),(2,'b','b');
root@bogon:/usr/local/mysql/bin# mkdir bak
root@bogon:/usr/local/mysql/bin# ./mysqldump t2 emp -T ./bak
root@bogon:/usr/local/mysql/bin# ls ./bak emp.sql emp.txt
root@bogon:/usr/local/mysql/bin# more ./bak/emp.sql -- MySQL dump 10.13 Distrib 5.7.18, for Linux (x86_64) -- -- Host: localhost Database: t2 -- ------------------------------------------------------ -- Server version 5.7.18-log /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -- -- Table structure for table `emp` -- DROP TABLE IF EXISTS `emp`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `emp` ( `id` int(11) NOT NULL DEFAULT '0', `name` varchar(10) DEFAULT NULL, `context` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; -- Dump completed on 2017-09-21 12:07:38
root@bogon:/usr/local/mysql/bin# more ./bak/emp.txt 1 a a 2 b b
shell> mysqldump -uroot --compact --default-character-set=utf8 t2 emp > emp.sql
shell> mysqlimport [options] db_name textfile1
shell> mysqlshow [option] [db_name [tbl_name [col_name]]]
perror [options] [errorcode [errorcode]] zj@bogon:/usr/local/mysql/bin$ perror 30 OS error code 30: Read-only file system zj@bogon:/usr/local/mysql/bin$ perror 60 OS error code 60: Device not a stream zj@bogon:/usr/local/mysql/bin$ perror 30 60 OS error code 30: Read-only file system OS error code 60: Device not a stream
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有