mysql的设置更改root密码、连接、常用命令
生活随笔
收集整理的这篇文章主要介绍了
mysql的设置更改root密码、连接、常用命令
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
13.1 设置更改root密码
- 更改环境变量PATH ,增加mysql绝对路径
首次直接使用mysql会提示‘该命令不存在’,原因是还没有将该命令加入环境变量,如果要使用该命令,需要使用其绝对路径:/usr/local/mysql/bin/mysql,为了方便,先将其加入系统环境变量:
mysql命令路径暂时加入环境变量,系统重启后该变量会失效,若要永久生效,需要将其加入环境变量配置文件:
vi /etc/profile#在配置文件最后 把上面的命令加#执行source命令生效 [root@taoyuan ~]# source /etc/profile- 首次登陆
注: -p=passwd,使用密码登录,在此可以将密码直接输入在命令行(跟在-p后面,不加空格:-p'123456'<此处单引号可以不加,但是当密码中有特殊符号时必须加,所以在命令行输入密码时养成习惯:加单引号>),也可以不在命令行输入,只跟-p选项,然后根据提示信息:“Enter password”,输入密码进行登录(此方法不会暴露用户密码,安全)。
- 设置mysql 的root密码 && 更改
- 密码重置
注: 完成该操作之后就可以任意登录mysql了(无需密码),所以此时mysql安全性很差,平时配置文件中一定不要添加该参数!!
13.2 连接mysql
- 本机直接登陆
- 通过端口连接(TCP/IP)
- 使用sock的连接
- 连接mysql操作一个命令
13.3 mysql常用命令
#查询库 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec)#切换库 mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed#查看库里的表 mysql> show tables;#查看字段 mysql> desc user;#查看建表语句 mysql> show create table user\G; #\G 表示:竖排显示#查看当前用户 mysql> select user(); +----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec)#查看当前使用的数据库 mysql> select database(); +------------+ | database() | +------------+ | NULL | +------------+ 1 row in set (0.00 sec)mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed mysql> select database(); +------------+ | database() | +------------+ | mysql | +------------+ 1 row in set (0.00 sec)#创建库 mysql> create database db1; Query OK, 1 row affected (0.00 sec)mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | db1 | | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.00 sec)#创建表 mysql> use db1; Database changed mysql> create table t1(`id` int(4), `name` char(40)); Query OK, 0 rows affected (0.02 sec)mysql> show create table t1\G; *************************** 1. row ***************************Table: t1 Create Table: CREATE TABLE `t1` (`id` int(4) DEFAULT NULL,`name` char(40) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec)ERROR: No query specified #ENGINE=InnoDB DEFAULT CHARSET=latin1 可以自定义 #如下 mysql> drop table t1; #删除t1表 Query OK, 0 rows affected (0.01 sec) mysql> create table t1(`id` int(4), `name` char(40)) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.01 sec)mysql> show create table t1\G; *************************** 1. row ***************************Table: t1 Create Table: CREATE TABLE `t1` (`id` int(4) DEFAULT NULL,`name` char(40) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 1 row in set (0.00 sec)ERROR: No query specified#查看当前数据库版本 mysql> select version(); +-----------+ | version() | +-----------+ | 5.6.35 | +-----------+ 1 row in set (0.00 sec)#查看数据库状态 mysql> show status;#查看各参数 mysql> show variables #指定的参数 mysql> show variables like 'max_connect%'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | max_connect_errors | 100 | | max_connections | 151 | +--------------------+-------+ 2 rows in set (0.00 sec)#修改参数 mysql> set global max_connect_errors=1000; Query OK, 0 rows affected (0.00 sec) #只在内存中生效#查看队列 mysql> show processlist; +----+------+-----------+------+---------+------+-------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+------+---------+------+-------+------------------+ | 9 | root | localhost | db1 | Query | 0 | init | show processlist | +----+------+-----------+------+---------+------+-------+------------------+ 1 row in set (0.00 sec)mysql> show full processlist; +----+------+-----------+------+---------+------+-------+-----------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+------+---------+------+-------+-----------------------+ | 9 | root | localhost | db1 | Query | 0 | init | show full processlist | +----+------+-----------+------+---------+------+-------+-----------------------+ 1 row in set (0.00 sec) #full 查看完整的队列小常识:
敲过的命令历史在mysql_history 文件里
转载于:https://blog.51cto.com/3622288/2060499
总结
以上是生活随笔为你收集整理的mysql的设置更改root密码、连接、常用命令的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: vba操作IE浏览器
- 下一篇: 猎头,希望您能更理解找工作的人