Mysql常用设置

初次安装mysql设置

第一种方式:修改mysql的配置文件

环境:centos7.4 , mysql5.7

1、 vim /etc/my.cnf 在[mysqld]加入 skip-grant-tables 然后保存退出 然后重启mysql

2、 ./etc/init.d/mysqld restart 登录

3、 mysql -u root -p

4、 5.7版本前的mysql运行: update user set password="你的密码" where user="用户"; 5.7版本后的mysql运行:update mysql.user set authentication_string=‘你的密码' where user='用户';

5、 exit; #退出

6 、编辑my.cnf文件删掉skip-grant-tables 这一行,然后重启MySQL,/etc/init.d/mysqld restart,否则MySQL仍能免密码登录

第二种方式:查看日志获得初始默认密码

1、cat /var/log/mysqld.log | grep password

2 、mysql -u root -p输入密码

3、 ALTER USER 'root'@'localhost' IDENTIFIED BY '1234';

Mysql 基础操作

1、查询操作

select count(*) from mysql.db
select * from mysql.db
select db.user from
select * from mysql.db where host like '192.168.%';

2、增加操作

insert into db1.t1 values (1,'abc');

3、修改操作

update db1.t1 set name='aaa' where id=1;

4、删除操作

truncate table db1.t1;
drop table db.t1;

原文地址:https://www.cnblogs.com/bianjiangjiang/p/13558658.html