Mysql5.7基础教程

hmysql5.7安装请参考
https://blog.csdn.net/qq_34962337/article/details/82353082
1,mysql关闭的几种方法

 mysqladmin -u root -p shutdown --mysqladmin关闭mysql
 /etc/init.d/mysqld stop --mysqld脚本关闭
 systemctl stop  mysqld --mysql脚本关闭
 kill -9 进程  --先查看mysqld进程,但不推荐方法

2,mysql修改密码
1

 alter user root@'localhost' identified by '654321';
 flush privileges;

2

 mysqladmin -u root  -p  password  123456 

3

mysql> use mysql
mysql> update mysql.user set authentication_string=password('6543216') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

4

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('7654321');
mysql> flush privileges;

5
忘记root密码,修root修改密码

/etc/init.d/mysqld stop --关闭mysql
mysqld_safe --skip-grant-tables & --安全模式启动
mysql> use mysql
mysql> update mysql.user set authentication_string=password('6543216') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
/etc/init.d/mysqld restart --重启mysql

3,mysql基础语法
1,mysql添加普通用户

mysql> create user 'test'@'localhost' identified by '123456';
mysql> flush privileges;
mysql> grant select on *.* to 'test2'@'localhost' identified by '654321';
mysql> flush privileges;

2
授权mysql用户和回收权限

mysql> grant select,insert on mydb.* to 'test'@'localhost';
mysql> show grants for 'test'@'localhost'; --查看权限
mysql> revoke select on mydb.* from  'test'@'localhost'; --回收select权限
mysql> flush privileges;

3
基础语句

create database mydb default charset utf8; --创建数据库
mysql> use mydb; --使用数据库
mysql> create table emm(id int); --创建表
mysql> insert into emm value(1); --插入数据
mysql> select * from emm; --查看表中数据 
mysql> update emm set id=2 where id=1; --更新数据
mysql> show tables; --查看库中表
mysql> desc emm; --查看表结构
mysql> alter table emm add column age int after id; --添加一个字段
mysql> show engines; --查看数据库支持的引擎
mysql> show variables like '%char%'; --查看字符集
mysql> show variables like '%max_con%'; --查看默认连接数
mysql> show OPEN TABLES where In_use > 0; --查看正在使用的表
mysql> SHOW ENGINE INNODB STATUS; --查看innodb日志

更多教程请参考

猜你喜欢

转载自blog.csdn.net/qq_34962337/article/details/82356384