MySql常用命令

1、启动,可以加参数--skip-grant-table

%mysql_home%/bin/mysqld --user=mysql
mysqld --console
mysqladmin -u root shutdown 

指定启动时绑定的IP地址:在my.cnf中的[mysqld]字段中加入一行

bind-addr  = 1.1.1.1

查看启动文件查找次序

mysqld --verbose --help |grep my.cnf

2、登录

%mysql_home%/bin/mysql -u root -p -h xxx.xxx.xxx.xxx

3、停止

%mysql_home%/bin/mysqladmin -u root -p shutdown

4、

show databases;
show processlist;
select * from information_schema. USER_PRIVILEGES ;
select user,host from mysql.user;
show grants for root@'localhosts';
grant all privileges on *.* to root@'localhost'  with grant option;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.28.251' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;
--
create database jbpm;
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON jbpm.* TO 'jbpm'@'%' IDENTIFIED BY '123456' with grant option;

5、 root无法登陆
mysql -u root -p
提示”Access denied for user ‘root’@’localhost’ (using password: YES)”

5.1 先想法登录,用--skip-grant-table启动

%mysql_home%/bin/mysqld --user=mysql --skip-grant-tables
%mysql_home%/bin/mysql -u root -p
如果输入密码无法登陆,尝试不用密码登录
%mysql_home%/bin/mysql

5.2
查看user表信息

mysql> select user,host from user;

如果没有user@localhost只有user@%,执行

update user set host = 'localhost' where user='root' and host = '%';

如果是密码错误,更改root@localhost密码

update mysql.user set password = password('123456') where user='root' and host='localhost';

6、MySQL无法启动,问你3306是否被占用

我这个是IP不对,而不是3306被占用晕,提示能不能精确点。
7、 日志

参考:[mysqlbinlog](https://www.cnblogs.com/martinzhang/p/3454358.html)

mysql> show variables like 'log_%'; 
    +----------------------------------------+---------------------------------------+
    | Variable_name                          | Value                                 |
    +----------------------------------------+---------------------------------------+
    | log_bin                                | ON                                    | ------> ON表示已经开启binlog日志

--------------
1.      mysql> show master logs;  //查看所有binlog日志列表
2.      mysql> show master status;  查看master状态,即最后(最新)一个binlog日志的编号名称,及其最后一个操作事件pos结束点(Position)值
3. mysql> flush logs;   刷新log日志,自此刻开始产生一个新编号的binlog日志文件
4.   mysql> reset master;  //重置(清空)所有binlog日志
     

你可能感兴趣的:(MySql常用命令)