码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2018-03-22 15:29:28      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:13.1 设置更改root密码 13.2

13.1 设置更改root密码

技术分享图片
[root@martin001 init.d]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@martin001 init.d]# PATH=$PATH:/usr/local/mysql/bin
[root@martin001 init.d]# vim /etc/profile
[root@martin001 init.d]# source /etc/profile
[root@martin001 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)
[root@martin001 init.d]# mysqladmin -uroot password ‘martin.1‘
Warning: Using a password on the command line interface can be insecure.
[root@martin001 init.d]# mysql -uroot
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
[root@martin001 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密码:
[root@martin001 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

技术分享图片
[root@martin001 ~]# 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)
[root@martin001 ~]# 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
[root@martin001 ~]# 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

原文地址:http://blog.51cto.com/12058686/2089849

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!