300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > mysql 常见密码设置_设置mysql用户密码(5.6/5.7) 远程连接数据库 常用命令

mysql 常见密码设置_设置mysql用户密码(5.6/5.7) 远程连接数据库 常用命令

时间:2019-07-09 16:45:52

相关推荐

mysql 常见密码设置_设置mysql用户密码(5.6/5.7) 远程连接数据库 常用命令

注: 以上命令均需要在mysql下执行;在mysql中每行命令末尾加上分号,表示该行命令执行结束。 tb_name即table name()表名。

示例:

[root@centos-01inux mysql]# mysql -uroot -p'123456'

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 5

Server version: 5.6.35 MySQL Community Server (GPL)

Copyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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 -A

Database changed

mysql> show tables;

+---------------------------+

| Tables_in_mysql |

+---------------------------+

| columns_priv |

| db |

| event |

| func |

| time_zone |

| time_zone_leap_second |

+---------------------------+

28 rows in set (0.00 sec)

mysql> desc time_zone;

+------------------+------------------+------+-----+---------+----------------+

| Field | Type | Null | Key | Default | Extra |

+------------------+------------------+------+-----+---------+----------------+

| Time_zone_id | int(10) unsigned | NO | PRI | NULL | auto_increment |

| Use_leap_seconds | enum('Y','N') | NO | | N | |

+------------------+------------------+------+-----+---------+----------------+

2 rows in set (0.11 sec)

mysql> show create table time_zone\G;

#G=grep筛选文字内容,规律显示出来

1. row

Table: time_zone

Create Table: CREATE TABLE time_zone (

Time_zone_id int(10) unsigned NOT NULL AUTO_INCREMENT,

Use_leap_seconds enum('Y','N') NOT NULL DEFAULT 'N',

PRIMARY KEY (Time_zone_id)

) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Time zones'

1 row in set (0.03 sec)

ERROR:

No query specified

mysql> select user();

+----------------+

| user() |

+----------------+

| root@localhost |

+----------------+

1 row in set (0.07 sec)

mysql> select database();

+------------+

| database() |

+------------+

| mysql |

+------------+

1 row in set (0.00 sec)

mysql> select * from user\G;

创建库:

mysql> create database db1;

Query OK, 1 row affected (0.02 sec)

创建表:

mysql> use db1;

#先切换到指定库下

Database changed

mysql> create table t1(id int(4),name char(40));

#括号中是定义字段及字段格式,使用反引号引起来

Query OK, 0 rows affected (1.51 sec)

mysql> select version();

+-----------+

| version() |

+-----------+

| 5.6.35 |

+-----------+

1 row in set (0.06 sec)

mysql> show status;

+-----------------------------------------------+-------------+

| Variable_name | Value |

+-----------------------------------------------+-------------+

| Aborted_clients | 0 |

| Aborted_connects | 0 |

+-----------------------------------------------+-------------+

mysql> show variables\G;

mysql> show variables like 'max_connect%'\G;

#like表示匹配;%是通配符

更改参数:

mysql> set global max_connect_errors=110;

Query OK, 0 rows affected (0.04 sec)

#在此只是临时更改,如果要永久更改,需要编辑配置文件

查看队列:

mysql> show processlist;

+----+------+-----------+------+---------+------+-------+------------------+

| Id | User | Host | db | Command | Time | State | Info |

+----+------+-----------+------+---------+------+-------+------------------+

| 5 | root | localhost | db1 | Query | 0 | init | show processlist |

+----+------+-----------+------+---------+------+-------+------------------+

1 row in set (0.01 sec)

mysql> drop table t1;

Query OK, 0 rows affected (0.32 sec)

mysql> drop database db1;

Query OK, 0 rows affected (0.10 sec)

扩展:MySQL5.7之更改root密码

与MySQL 5.6版本不同,在安装MySQL 5.7过程中(初始化)会自动生成root用户密码(随机),那么在安装完成后如何更改root用户密码?步骤如下:

查看默认密码

[root@centos-01inux mysql]# cat /root/.mysql_secret

#The random password set for the root userat Fri Jan 10 20:00:34 (local time): 3A)2DdJLkcFP

更改root密码:已知默认密码

使用默认密码登录:

[root@centos-01inux mysql]# /usr/local/mysql/bin/mysql -uroot -p'3A)2DdJLkcFP'

Welcome to the MySQL monitor.

Your MySQL connection id is 3

Server version: 5.7.17

设置新密码:

方法1:

mysql> set password = password('123456');

Query OK, 0 rows affected, 1 warning (0.00 sec)

方法2:

mysql> SET PASSWORD FOR 'root'@localhost = PASSWORD('123456');

mysql> quit

Bye

Finished!

更改root密码:不知道默认密码

编辑配置文件:

[root@centos-01inux mysql]# vi /etc/f

[mysqld]

skip-grant-tables

datadir=/data/mysql

socket=/tmp/mysql.sock

#增加参数:skip-grant-tables

重启:

[root@centos-01inux mysql]# /etc/init.d/mysqld restart

登录:此时不需要密码

[root@centos-01inux mysql]# /usr/local/mysql/bin/mysql -uroot

更改密码:

mysql> update user set authentication_string=password('12456') where user='root';

mysql>quit

[root@centos-01inux mysql]# vi /etc/f

[mysqld]

datadir=/data/mysql

socket=/tmp/mysql.sock

重启:

[root@centos-01inux mysql]# /etc/init.d/mysqld restart

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。