mysql常用命令
2022/8/8 2:22:46
本文主要是介绍mysql常用命令,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1. 启动mysql服务: net start mysql
或者
service mysql start
或者
systemctl start mysqld
或者
/etc/init.d/mysqld start
或者
sh $MYSQL_HOME/support-files/mysql.server start
2. 关闭mysql服务: net stop mysql
3. 以root用户登录: mysql -h localhost -u root -p 换行输入密码;
mysql -u devuser -p
4. 创建数据库: create schema [数据库名称] default character set utf8 collate utf8_general_ci;
create database devdatabase;
采用create schema和create database创建数据库的效果一样;
5. 创建用户: CREATE USER 'username'@'host' IDENTIFIED BY 'password';
如: create user 'devuser'@'localhost' identified by '123456';
如: create database boarddatabase default character set utf8 collate utf8_general_ci;
6. 授权: GRANT privileges ON databasename.tablename TO username@host identified by 'password';
其中: @"%" 表示对所有非本地主机授权,不包括localhost;
如: grant all privileges on devdatabase.* to devuser@localhost identified by '123456';
grant all privileges on *.* to 'devuser'@'%' identified by '123456';
grant all privileges on *.* to 'root'@'%' identified by '123456';
7. flush privileges;--立即启用修改
8. revoke all on *.* from tester;--取消用户所有数据库(表)的所有权限
9. 删除用户: delete from mysql.user where user='devuser';
10. 删除数据库: drop database databasename; 如: drop database 'devuser';
11. 退出命令行: exit;
12. 查看数据库(使用devuser登录): show databases;
13. 切换数据库: use databasename;
如: use devdatabase;
这篇关于mysql常用命令的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-24MySQL集群部署入门教程
- 2024-12-24部署MySQL集群学习:新手入门教程
- 2024-12-24部署MySQL集群入门:一步一步搭建指南
- 2024-12-07MySQL读写分离入门:轻松掌握数据库读写分离技术
- 2024-12-07MySQL读写分离入门教程
- 2024-12-07MySQL分库分表入门详解
- 2024-12-07MySQL分库分表入门指南
- 2024-12-07MySQL慢查询入门:快速掌握性能优化技巧
- 2024-12-07MySQL入门:新手必读的简单教程
- 2024-12-07MySQL入门:从零开始学习MySQL数据库