MySql 常用命令及问题处理

来源:互联网 发布:mac上的照片管理软件 编辑:程序博客网 时间:2024/06/09 22:29

启动等

启动:

1、使用 service 启动:service mysqld start
2、使用 mysqld 脚本启动:/etc/init.d/mysqld start
3、使用 safe_mysqld 启动:safe_mysqld&

停止

1、使用 service 启动:service mysqld stop
2、使用 mysqld 脚本启动:/etc/init.d/mysqld stop
3、 mysqladmin shutdown

重启

1、使用 service 重启:service mysqld restart
2、使用 mysqld 脚本重启:/etc/init.d/mysqld restart

LNMP状态管理命令:

LNMP状态管理: /root/lnmp {start|stop|reload|restart|kill|status}
Nginx状态管理:/etc/init.d/nginx {start|stop|reload|restart}
MySQL状态管理:/etc/init.d/mysql {start|stop|restart|reload|force-reload|status}
Memcached状态管理:/etc/init.d/memcached {start|stop|restart}
PHP-FPM状态管理:/etc/init.d/php-fpm {start|stop|quit|restart|reload|logrotate}
PureFTPd状态管理: /etc/init.d/pureftpd {start|stop|restart|kill|status}
ProFTPd状态管理: /etc/init.d/proftpd {start|stop|restart|reload}

如重启LNMP,输入命令:/root/lnmp restart 即可,单独重启>mysql:/etc/init.d/mysql restart

LNMPA状态管理命令:

LNMPA状态管理: /root/lnmpa {start|stop|reload|restart|kill|status}
Nginx状态管理:/etc/init.d/nginx {start|stop|reload|restart}
MySQL状态管理:/etc/init.d/mysql {start|stop|restart|reload|force-reload|status}
Memcached状态管理:/etc/init.d/memcached {start|stop|restart}
PureFTPd状态管理: /etc/init.d/pureftpd {start|stop|restart|kill|status}
ProFTPd状态管理: /etc/init.d/proftpd {start|stop|restart|reload}
Apache状态管理:/etc/init.d/httpd {start|stop|restart|graceful|graceful-stop|configtest|status}

Windows下表名区分大小写,在my.ini里的[mysqld]字段加:
lower_case_table_names = 0

PhpMyAdmin命令

修改密码

phpmyadmin -u root password ‘root’

MySql命令

查看用户权限

show grants for username@localhost;

查看数据库

show database dbname;

查看表结构

describe 表名;

查看表

show table tickets;

修改root密码,用root 进入mysql后

mysql>set password =password(‘你的密码’);

更新权限

mysql>flush privileges;

创建用户

create user ‘33’@’localhost’ identified by ‘aaaa’; //创建一个33用户,密码为aaaa

或:

insert into mysql.user(Host,User,Password) values(“localhost”,”admin”,password(“admin”));

查看一下mysql下的user

select * from mysql.user where user=’33’ or user=’44’;

test用户拥有test数据库下的所有操作

grant all ON test.* TO ‘test’@’localhost’;

test用户可以对test数据库下user表,进行查找和更新操作

grant select,update on test.user to ‘test’@’localhost’;

//授权admin用户拥有mydb数据库的所有权限。

grant all privileges on mydb.* to admin@localhost identified by ‘admin’;

//修改密码

update mysql.user set password=password(‘新密码’) where User=”admin” and Host=”localhost”;

//设置远程登陆,注意@后的ip是允许从这个IP登陆,如果不限用%

grant all PRIVILEGES on test.* to andy@’192.168.1.100’ identified by ‘123456’;
GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘youpassword’ WITH GRANT OPTION;
message from server:Host ” is not allowed to connect to this MySql server

执行grant all PRIVILEGES 。。。语句。

查看索引

show index 表名

查看执行情况

explain 语句

表结构管理

添加字段

alter table table1 add id int unsigned not Null auto_increment primary key;
alter table table1 add column_name varchar(16) not Null;

0 0
原创粉丝点击