时间:2021-07-01 10:21:17 帮助过:19人阅读
安装了mysql后可以使用mysql命令。
查询当前用户:
select user();
CREATE USER ‘uacuser1‘@‘localhost‘ IDENTIFIED BY ‘123456‘;
CREATE USER ‘uacuser1‘@‘aipaas03‘ IDENTIFIED BY ‘123456‘;
CREATE USER ‘uacuser1‘@‘%‘ IDENTIFIED BY ‘123456‘;
查询用户
select user,host from mysql.user order by user;
删除用户:
Delete FROM mysql.user Where User=‘uacdb‘ and Host=‘localhost‘;
Delete FROM mysql.user Where User=‘uacdb‘ and Host=‘aipaas03‘;
Delete FROM mysql.user Where User=‘uacdb‘ and Host=‘%‘;
flush privileges;
create database uacdb;
GRANT ALL PRIVILEGES ON uacdb.* TO uacuser1@"%" IDENTIFIED BY "123456";
GRANT ALL PRIVILEGES ON uacdb.* TO uacuser1@"localhost" IDENTIFIED BY "123456";
GRANT ALL PRIVILEGES ON uacdb.* TO uacuser1@"aipaas03" IDENTIFIED BY "123456";
flush privileges;
- mysql新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效。
- mysql建库必须用root建,然后赋权用户。
查询数据库:
show databases;
进入某个数据库(database_name是具体的库名):
use database_name;
删除数据库:
drop database if exists database_name;
必须进入某个库后才能进行。
DROP TABLE IF EXISTS `auth_center`;
CREATE TABLE `auth_center` (
`AUTH_ID` bigint(20) NOT NULL AUTO_INCREMENT,
`AUTH_PASSWORD` varchar(48) COLLATE utf8_bin NOT NULL,
`AUTH_SOURCE` varchar(16) COLLATE utf8_bin NOT NULL DEFAULT ‘‘,
`AUTH_PARAM` varchar(2048) COLLATE utf8_bin DEFAULT NULL,
`AUTH_STATE` varchar(2) COLLATE utf8_bin NOT NULL,
`AUTH_REGISTER_TIME` timestamp NOT NULL,
`AUTH_ACTIVE_TIME` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`AUTH_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=617 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
查询表:
show tables;
查看表结构:
desc table_name;
DML:
使用标准的DML即可。select、insert、update、delete。
show variables like ‘%autocommit%‘;
mysql –V
mysql --help | grep Distrib
status
select version();
quit
exit
ERROR 1044 (42000): Access denied for user ‘portaluser1’@’aipaas03’ to database ‘protaldb’
解决:use protaldb时遇到,protaldb写错了;create database时遇到,必须用root用户。
ERROR 1045 (28000): Access denied for user ‘root’@’aipaas03’ (using password: YES)
解决:用户名或者密码错了。
ERROR 1046 (3D000): No database selected
解决:要先use 库名。
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
解决:登录时遇到。需要-h mysql所在主机。或者用mysql的用户登录主机。
ERROR 2006 (HY000): MySQL server has gone away
解决:grant all privileges 时遇到,可忽略。
2015.6.20
MySQL常用命令
标签:mysql 命令