13.1 设置更改root密码 13.2 连接mysql 13.3 mysql常用命令
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了13.1 设置更改root密码 13.2 连接mysql 13.3 mysql常用命令相关的知识,希望对你有一定的参考价值。
13.1 设置更改root密码
[[email protected] init.d]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[[email protected] init.d]# PATH=$PATH:/usr/local/mysql/bin
[[email protected] init.d]# vim /etc/profile
[[email protected] init.d]# source /etc/profile
[[email protected] init.d]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.35 MySQL Community Server (GPL)
[[email protected] init.d]# mysqladmin -uroot password ‘martin.1‘
Warning: Using a password on the command line interface can be insecure.
[[email protected] init.d]# mysql -uroot
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
[[email protected] init.d]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.35 MySQL Community Server (GPL)
知道root密码,修改root密码:
[[email protected] init.d]# mysqladmin -uroot -p‘martin.1‘ password ‘martin.2‘
Warning: Using a password on the command line interface can be insecure.
不知道root密码的情况下修改root密码:
修改/etc/my.cnf 第一行添加 skip-grant
重启mysql服务 /etc/init.d/mysqld restart
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 -A
Database changed
mysql> select * from user where user=‘root‘;
mysql> update user set password=password(‘martinlinux‘) where user=‘root‘;
Query OK, 4 rows affected (0.02 sec)
Rows matched: 4 Changed: 4 Warnings: 0
13.2 连接mysql
[[email protected] ~]# mysql -uroot -p‘martinlinux‘ -h127.0.0.1 -P3306
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.35 MySQL Community Server (GPL)
[[email protected] ~]# mysql -uroot -p‘martinlinux‘ -S/tmp/mysql.sock
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
[[email protected] ~]# mysql -uroot -p‘martinlinux‘ -e "show databases"
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
13.3 mysql常用命令
创建库 create database db1;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db1 |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.01 sec)
创建表 use db1; create table t1(id
int(4), name
char(40));
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.01 sec)
查看当前数据库版本 select version();
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.6.35 |
+-----------+
1 row in set (0.00 sec)
查看数据库状态 show status;
mysql> show status;
+-----------------------------------------------+-------------+
| Variable_name | Value |
+-----------------------------------------------+-------------+
| Aborted_clients | 0 |
| Aborted_connects | 4 |
| Binlog_cache_disk_use | 0 |
| Binlog_cache_use | 0 |
| Binlog_stmt_cache_disk_use | 0 |
| Binlog_stmt_cache_use | 0 |
| Bytes_received | 1634 |
| Bytes_sent | 69469 |
查看各参数 show variables; show variables like ‘max_connect%‘;
mysql> show variables like ‘max_connect%‘;
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| max_connect_errors | 100 |
| max_connections | 151 |
+--------------------+-------+
2 rows in set (0.00 sec)
修改参数 set global max_connect_errors=1000;
mysql> set global max_connect_errors = 1000;
Query OK, 0 rows affected (0.01 sec)
查看队列 show processlist; show full processlist;
mysql> show processlist;
+----+------+-----------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+-------+------------------+
| 10 | root | localhost | db1 | Query | 0 | init | show processlist |
+----+------+-----------+------+---------+------+-------+------------------+
1 row in set (0.01 sec)
mysql> show full processlist;
+----+------+-----------+------+---------+------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+-------+-----------------------+
| 10 | root | localhost | db1 | Query | 0 | init | show full processlist |
+----+------+-----------+------+---------+------+-------+-----------------------+
1 row in set (0.00 sec)
以上是关于13.1 设置更改root密码 13.2 连接mysql 13.3 mysql常用命令的主要内容,如果未能解决你的问题,请参考以下文章
13.1 设置更改root密码13.2 连接mysql13.3 mysql常用命令
13.1 设置更改root密码;13.2 连接MySQL;13.3 MySQL常用命令
13.1 设置更改root密码;13.2 连接MySQL;13.3 MySQL常用命令