您的位置:首页 > 数据库 > MySQL

13.1 设置更改root密码;13.2 连接MySQL;13.3 MySQL常用命令

2017-08-21 16:51 966 查看
扩展 :
mysql5.7 root密码更改 http://www.apelearn.com/bbs/thread-7289-1-1.html myisam 和innodb引擎对比 http://www.pureweber.com/article/myisam-vs-innodb/ mysql 配置详解: http://blog.linuxeye.com/379.html mysql调优: http://www.aminglinux.com/bbs/thread-5758-1-1.html 同学分享的亲身mysql调优经历: http://www.apelearn.com/bbs/thread-11281-1-1.html 13.1 设置更改root密码
1. 搜索mysql进程是否启动:
[root@hao-01 ~]# ps aux |grep mysql
2. 启动mysqld服务:
[root@hao-01 mysql]# /etc/init.d/mysqld start
3. 给mysql设定环境变量:
[root@hao-01 ~]# export PATH=$PATH:/usr/local/mysql/bin/
4. 永久生效,把mysql环境变量,添加到/etc/profile配置文件:
[root@hao-01 ~]# vim /etc/profile
添加内容(在末尾添加):
export PATH=$PATH:/usr/local/mysql/bin/




5. 使其/etc/profile配置文件中的mysql变量,立即生效:
[root@hao-01 ~]# source /etc/profile
6. mysql设置 登录密码:
[root@hao-01 ~]# mysqladmin -uroot password 'haomima1'
7. 指定mysql密码,登录mysql:
[root@hao-01 ~]# mysql -uroot -p




8. 更改mysql密码(知道原登录密码的前提下更改!)
[root@hao-01 ~]# mysqladmin -uroot -p'haomima1' password 'haomima2'
重置mysql密码:
1. 更改my.cnf配置文件,在[mysqld]下添加一行内容:
[root@hao-01 ~]# vim /etc/my.cnf
添加内容(忽略授权):
skip-grant




2. 重启mysqld服务:
[root@hao-01 ~]# /etc/init.d/mysqld restart
3. 登录mysql的root用户(原有登录密码此时忽略不进行验证了)
[root@hao-01 ~]# mysql -uroot
4. 切换到mysql库:
mysql> use mysql;
5. 重新定义root用户的登录密码:
mysql> update user set password=password('haomima') where user='root';



6. 退出mysql登录状态:
mysql> quit
7. 把my.cnf配置文件中[mysqld]下行刚刚添加的skip-grant删除:
[root@hao-01 ~]# vim /etc/my.cnf
删除如下行:
skip-grant




8. 重启mysqld服务:
[root@hao-01 ~]# /etc/init.d/mysqld restart
13.2 连接MySQL
1. 指定用户名 密码 连接登录mysql
[root@hao-01 ~]# mysql -uroot -p'haomima'
2. 指定用户名 密码 myslq文件 连接登录mysql
[root@hao-01 ~]# mysql -uroot -p'haomima' -S/tmp/mysql.sock
3. 指定用户名 密码 远程mysql库ip 端口 连接登录mysql
[root@hao-01 ~]# mysql -uroot -p'haomima' -h127.0.0.1 -P3306
4. 指定用户名 密码 连接登录mysql -e指定执行的命令
[root@hao-01 ~]# mysql -uroot -p'haomima' -e "show databases"
13.3 MySQL常用命令
1. 查询有哪些数据库:
mysql> mysqlshow databases;



2. 切换到指定库下:
mysql> use mysql;




3. (进入库)查看库里所有的表:
mysql> show tables;
4. 查看指定表里的字段:
mysql> desc user;
5. 查看表怎么创建的:
mysql> show create table user\G;
6. 查看当前登录用户:
mysql> select user();




7. 查看当前使用的数据库:
mysql> select database();



8. 创建库:
mysql> create database ceshiku;
9. 切换到ceshiku库:
mysql> use ceshiku;
10. 创建表(biao1):
{ 定义:字段1(ziduan1) 格式(int(4)) 字段2(ziduan2)格式(char(40)) }
mysql>create table biao1(`ziduan1` int(4), `ziduan2` char(40));
11. 查看当前数据库版本:
mysql> select version();




12. 查看数据库状态:
mysql> show status;
13. 查看各参数:
mysql> show variables;
14. 查看max_connect相关的参数:
mysql> show variables like 'max_connect%';




15. 修改max_connect_errors参数=1000 :
mysql> set global max_connect_errors=1000;
16. 永久生效更改的参数,需要编辑/etc/my.cnf配置文件中对应的参数: [root@hao-01 ~]# vim /etc/my.cnf
17. 查看队列 :
mysql> show processlist;
18. 查看到完整的队列:
(mysql有哪些命令在连接,都在做什么等)
mysql> show full processlist;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  MySQL常用命令