MySQL是一种广泛使用的关系型数据库管理系统,为了更好地管理和维护数据库,以下是一些常用的MySQL数据库操作指南。
SHOW DATABASES LIKE [表名];
DROP DATABASE [表名];
SHOW TABLES;
SHOW CREATE TABLE [表名];
DESC [表名];
ALTER TABLE [原表名] RENAME TO [新表名];
SELECT * FROM information_schema.`COLUMNS` WHERE COLUMN_NAME = [字段名] AND TABLE_SCHEMA = [表名];
mysqldump -u[用户名] -p[密码] [数据库名] > [生成脚本文件路径];
方法一(不用登录):
mysql -u[用户名] -p[密码] [数据库名] < [脚本文件路径];
方法二(切换到待恢复数据库):
source [脚本文件路径];
CREATE TABLE [B表名] LIKE [A表名];
INSERT INTO [B表名] SELECT * FROM [A表名];
REPLACE INTO [B表名] SELECT * FROM [A表名];
CREATE TABLE [B表名] SELECT * FROM [A表名];
UPDATE [表名] SET [待修改字段] = DATE_ADD([待修改字段], INTERVAL 7 DAY);
UPDATE [表名] SET [待修改字段] = DATE_SUB([待修改字段], INTERVAL 1 MONTH);
FROM_UNIXTIME([时间戳], '%Y-%m-%d %H:%i:%S');
UNIX_TIMESTAMP(NOW());
SHOW VARIABLES LIKE 'char%';
SELECT @@tx_isolation;
SET transaction isolationlevel [4 选 1];
SHOW VARIABLES LIKE '%max_connections%';
SET GLOBAL max_connections = 200;
ALTER TABLE T_PAY_ORDER ENGINE = InnoDB;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;