做完这40道题,再也不用担心MySQL命令了,废话不多说,咱们直接上干货!!!
service mysqld start
/init.d/mysqld start
safe_mysql &
service mysqld stop
/etc/init.d/mysqld stop
mysqladmin -uroot -p123456 shutdown
lsof -i:3306
netstat -tunlp|grep 3306
ss -tulnp|grep 3306
方法一
mysqladmin -u root -p123456 password 'abc123' #比较常用
方法二(sql 语句修改)
update mysql.user set password=password(123456) where user='root' and host ='localhost';
flush privileges;
方法三(sql 语句修改)
set password=password('abc123');
单实例登陆
mysql -uroot -p123456
多实例登陆
mysql -uroot -p123456 -S /data/3306/mysql.sock
show variables like "%charac%";
# mysql -V
select version();
select user();
create database smallstudent default character set gbk;
show create database smallstudent;
grant select,update,insert,delete,alter on smallstudent.* to smallstudent@'localhost' i dentified by '123456';
show grants for smallstudent@'localhost';
select user,host from mysql.user;
use smallstudent();
create table test (id int(4),name varchar(16)) engine=InnoDB default charset=gbk;
desc test;
show create table test\G
insert into test (id,name) values (1,'smallstudent');
insert into test (id,name) values (2,'老男孩'),(3,'smallstudentedu');
select * from test where name='smallstudent';
update test set name='bigstudent' where id=1;
alter table test add age tinyint(2) after id;
system mysqldump -uroot -p123456 -B -x -F --events smallstudent >/opt/bak. sql
delete from test;
drop table test;
drop database smallstudent;
system mysql -uroot -p123456 </opt/bak.sql
alter database smallstudent default character set utf8;
alter table test default character set utf8;
alter table test add primary key(id);
方法一:
alter table test add index index_name(name);
方法二:
create index index_name on test(name);
alter table test add shouji char(11) after name;
insert into test (id,age,name,shouji) values ('4','27','wangning','13833573773');
insert into test (id,age,name,shouji) values ('5','30','litao','13833573773');
方法一:
alter table test add index index_shouji(shouji(8));
方法二:
create index index_shouji on test(shouji(8));
show index from test\G
alter table test drop index index_name;
alter table test drop index index_shouji;
create index index_name_shouji on test(name(6),shouji(8));
select * from test where name='smallstudent' and shouji like "135%";
explain select * from test where name="smallstudent" and shouji like "135%" \G
alter table test engine=myisam; #myisam 不区分大小写
revoke select on smallstudent.* from smallstudent@'localhost';
drop user smallstudent@'localhost';
drop database smallstudent;
mysqladmin -uroot -p123456 shutdown
# pkill mysql #先关闭 mysql 服务
#使用--skip-grant-tables 启动 mysql,忽略授权登陆验证
# mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables &
# mysql #此时再登陆,已经不需要密码了
update mysql.user set password=password('abc123') where user='root' and host="localhost"; #设置新的密码
flush privileges;
# mysql -uroot -pabc123 #再次用新设置的密码登陆即可
如果您觉得文章有帮助,欢迎点赞收藏加关注,一连三击呀,感谢!!☺☻