码迷,mamicode.com
首页 > 系统相关 > 详细

2018-05-07 Linux学习

时间:2018-05-07 23:02:46      阅读:712      评论:0      收藏:0      [点我收藏+]

标签:Linux学习

13.1 设置更改root密码

/usr/local/mysql/bin/mysql -uroot
更改环境变量PATH,增加mysql绝对路径

mysqladmin -uroot password ‘123456‘
mysql -uroot -p123456

密码重置
vi /etc/my.cnf //增加skip-grant
重启mysql服务 /etc/init.d/mysqld restart
mysql -uroot
use mysql;
update user set password=password(‘aminglinux‘) where user=‘root‘;

操作过程

添加PATH
[root@linux-01 ~]# mysql -uroot
-bash: mysql: 未找到命令
[root@linux-01 ~]# ls /usr/local/mysql/bin/mysql
/usr/local/mysql/bin/mysql

[root@linux-01 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@linux-01 ~]# export PATH=$PATH:/usr/local/mysql/bin/
[root@linux-01 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin/

[root@linux-01 ~]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.39 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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>

设置密码

[root@linux-01 ~]# mysqladmin -uroot password ‘aminglinux.1‘
Warning: Using a password on the command line interface can be insecure.
[root@linux-01 ~]# mysql -uroot -p
Enter password: 
输入密码能正常登陆

更改密码

[root@linux-01 ~]# mysqladmin -uroot -p‘aminglinux.1‘ password ‘aminglinux.2‘
Warning: Using a password on the command line interface can be insecure.

[root@linux-01 ~]# mysql -uroot -p
Enter password: 
输入密码能正常登陆

重置密码 (不知密码)

[root@linux-01 ~]# vim /etc/my.cnf
[mysqld]
skip-grant
datadir=/data/mysql
socket=/tmp/mysql.sock

[root@linux-01 ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 
[root@linux-01 ~]# mysql -uroot

mysql> use mysql

mysql> select * from user;

mysql> update user set password=password(‘aminglinux‘) where user=‘root‘;

[root@linux-01 ~]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock

[root@linux-01 ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS!

[root@linux-01 ~]# mysql -uroot -p
Enter password: 
输入密码能正常登陆

13.2 连接MySQL

mysql -uroot -p123456
mysql -uroot -p123456 -h127.0.0.1 -P3306
mysql -uroot -p123456 -S/tmp/mysql.sock
mysql -uroot -p123456 -e “show databases”

[root@linux-01 ~]# mysql -uroot -paminglinux -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常用命令

查询库 show databases;
切换库 use mysql;
查看库里的表 show tables;
查看表里的字段 desc tb_name;
查看建表语句 show create table tb_name\G;
查看当前用户 select user();
查看当前使用的数据库 select database();

创建库 create database db1;
创建表 use db1; create table t1(id int(4), name char(40));
查看当前数据库版本 select version();
查看数据库状态 show status;
查看各参数 show variables; show variables like ‘max_connect%‘;
修改参数 set global max_connect_errors=1000;
查看队列 show processlist; show full processlist;

操作过程

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                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
28 rows in set (0.00 sec)

mysql> desc user;

mysql> show create table user\G;

mysql> select user();
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

会反解析登陆ip

[root@linux-01 ~]# mysql -uroot -paminglinux -h192.168.106.160

mysql> select user();
+---------------+
| user()        |
+---------------+
| root@linux-01 |
+---------------+
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 -A

Database 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> use db1;
Database changed

创建表

mysql> create table t1(`id` int(4), `name` char(40));
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=latin1
1 row in set (0.01 sec)

ERROR: 
No query specified

创建表,指定字符串

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.39    |
+-----------+
1 row in set (0.00 sec)

查看数据库状态

mysql> show status;
+-----------------------------------------------+-------------+
| Variable_name                                 | Value       |
+-----------------------------------------------+-------------+
| Aborted_clients                               | 0           |
| Aborted_connects                              | 0           |
| Binlog_cache_disk_use                         | 0           |
| Binlog_cache_use                              | 0           |

查看各参数

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> show variables like ‘slow%‘;
+---------------------+-------------------------------+
| Variable_name       | Value                         |
+---------------------+-------------------------------+
| slow_launch_time    | 2                             |
| slow_query_log      | OFF                           |
| slow_query_log_file | /data/mysql/linux-01-slow.log |
+---------------------+-------------------------------+
3 rows in set (0.00 sec)

修改参数,临时生效,若长期生效需要改配置文件 my.conf

mysql> set global max_connect_errors=1000;
Query OK, 0 rows affected (0.01 sec)

mysql> show variables like ‘max_connect%‘;
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| max_connect_errors | 1000  |
| max_connections    | 151   |
+--------------------+-------+
2 rows in set (0.01 sec)

查看队列

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.00 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)

2018-05-07 Linux学习

标签:Linux学习

原文地址:http://blog.51cto.com/9298822/2113778

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