Mysql常用操作

创建用户:

CREATE USER 'username'@'%' IDENTIFIED WITH mysql_native_password BY 'password';

创建数据库:

CREATE DATABASE databasename;

赋权:

grant all on databasename.* to 'username'@'%'; 
flush privileges;

收回赋权

REVOKE ALL PRIVILEGES ON databasename.* FROM 'username'@'%';

数据库导入导出:

# 导出(需要输入mysql的root密码)
# 先切换到root用户
cd /opt/mysql/bin ./mysqldump -uroot -p --single-transaction databasename> /app/software/databasename_20230308.sql
 -- 导入:先登入mysql,然后创建数据库进行导入
mysql -uroot -p create database `newdatabase`; use `newdatabase`; source /app/software/databasename_20230308.sql;

 修改AUTO_INCREMENT初始值:

ALTER TABLE `tablename` AUTO_INCREMENT = 1;

 查看历史记录:

# 查看用户历史操作
history
# 查看Mysql历史操作
cat ~/.mysql_history

 查看Mysql数据库所占空间

cd /app/mysql/data/
du -sh*

 批量导出建表语句

mysqldump -u username -p password --no-data databasename tablename1 tablename2 tablename3 > /tmp/database_3tables_20230728.sql

 

posted @ 2023-03-09 11:59  野生薄荷糖  阅读(15)  评论(0编辑  收藏  举报