1./etc/init.d/mysqld start
2.service mysqld start
3.systemctl start mysqld
1.lsof -i :3306
2.netstat -lntup |grep 3306
设置密码
1.mysql -uroot -ppassword -e "set passoword for root = password('passowrd')"
2.mysqladmin -uroot password "NEWPASSWORD"
更改密码
1.mysqladmin -uroot password oldpassword "NEWPASSWORD"
2.use mysql;
3.update user set passowrd = PASSWORD('newpassword') where user = 'root';
5.7的版本改成了如下:
(update mysql.user set authentication_string =PASSWORD('mxl20152873..')where user ='root';)或者也可以用(SET PASSWORD = PASSWORD('root(密码)');)
flush privileges;
获得初始密码
grep 'password' /usr/local/mysqld/log/mysql_error.log
如果还是不可以登录直接进入/etc/my.conf中加上skip-grant-tables跳过密码,然后MySQL进入数据库执行上面的修改密码即可
msyql 5.7以上版本修改默认密码命令
alter user 'root'@'localhost' identified by 'root'
mysql -uroot -ppassword
show create database DB_NAME;
1.mysql -V
2.mysql -uroot -ppassowrd -e "use mysql;select version();"
select user();
create database mingongge DEFAULT CHARSET GBK COLLATE gbk_chinese_ci;
grant all on mingongge.* to 'mingongge'@'localhost' identified by 'mingongge';
show grants for mingongge@localhost
select user from mysql.user;
use mingongge
create table test (id int(4),name varchar(16))ENGINE=innodb DEFAULT CHARSET=gbk;
1.desc test;
2.show create table test\G
insert into test values('1','mingongge');
insert into test values('2','民工哥'),('3','mingonggeedu');
select * from test where name = 'mingongge';
update test set name = 'mgg' where id = '1';
alter table test add age tinyint(2) after id;
system mysqldump -uroot -pMgg123.0. -B mingongge >/root/mingongge_bak.sql
1.delete from test;
2.select * from test;
1.drop table test;
2.show tables;
3.drop database mingongge;
4.show databases;
system mysql -uroot -pMgg123.0.
1.alter database mingongge default character set utf8;
2.alter table test default character set utf8;
1.alter table test add primary key(id);
2.create index mggindex on test(name(16));
1.alter table test add shouji char(11);
2.#默认就是在最后一列后面插入新增列
insert into test values('4','23','li','13700000001'),('5','26','zhao','13710000001');
create index SJ on test(shouji(8));
1.show index from test;
2.show create table test\G
3.#下面的命令也可以查看索引类型
4.show keys from test\G
1.drop index SJ on test;
2.drop index mggindex on test;
create index lianhe on test(name(6),shouji(8));
select * from test where shouji like '137%' and name = 'zhao';
explain select * from test where name = 'zhao' and shouji like '137%'\G
alter table test engine=MyISAM;
1
revoke select on mingongge.* from mingongge@localhost;
drop user migongge@localhost;
drop database mingongge
1.mysqladmin -uroot -pMgg123.0. shutdown
2.lsof -i :3306
1.mysqld_safe --skip-grant-tables & #启动数据库服务
2.mysql -uroot -ppassowrd -e "use mysql;update user set passowrd = PASSWORD('newpassword') where user = 'root';flush privileges;"