当前位置:Gxlcms > 数据库问题 > 13.1 设置更改root密码;13.2 连接MySQL;13.3 MySQL常用命令

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

时间:2021-07-01 10:21:17 帮助过:25人阅读

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. 登录mysqlroot用户(原有登录密码此时忽略不进行验证了)

[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. 查看完整的队列

人气教程排行