mysql_installation

MySQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
[root@master tmp]# ls
mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar vmware-tools-distrib
VMwareTools-10.3.10-13959562.tar.gz
[root@master tmp]# mkdir localrepo
[root@master tmp]# tar -xvf mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar -C /tmp/localrepo/
mysql-community-embedded-devel-5.7.26-1.el7.x86_64.rpm
mysql-community-libs-5.7.26-1.el7.x86_64.rpm
mysql-community-embedded-5.7.26-1.el7.x86_64.rpm
mysql-community-test-5.7.26-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.26-1.el7.x86_64.rpm
mysql-community-common-5.7.26-1.el7.x86_64.rpm
mysql-community-devel-5.7.26-1.el7.x86_64.rpm
mysql-community-client-5.7.26-1.el7.x86_64.rpm
mysql-community-server-5.7.26-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.26-1.el7.x86_64.rpm

[root@master tmp]# rpm -ivh localrepo/*.rpm
warning: ./mysql-community-client-5.7.26-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
mariadb-libs is obsoleted by mysql-community-libs-5.7.26-1.el7.x86_64
mariadb-libs is obsoleted by mysql-community-libs-compat-5.7.26-1.el7.x86_64
perl(JSON) is needed by mysql-community-test-5.7.26-1.el7.x86_64
[root@master tmp]#
[root@master localrepo]# rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm mysql-community-client-5.7.26-1.el7.x86_64.rpm mysql-community-libs-5.7.26-1.el7.x86_64.rpm mysql-community-common-5.7.26-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.26-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-5.7.26-1.e################################# [ 25%]
2:mysql-community-libs-5.7.26-1.el7################################# [ 50%]
3:mysql-community-client-5.7.26-1.e################################# [ 75%]
4:mysql-community-server-5.7.26-1.e################################# [100%]
[root@master tmp]# systemctl start mysqld
[root@master tmp]# vim /var/log/mysqld.log
2019-12-09T12:05:45.749699Z 1 [Note] A temporary password is generated for root@localhost: eYu.a<?Zp1Qg
...
...

[root@master tmp]# mysql -uroot -p
Enter password: (/var/log/mysqld.log中的临时密码)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26

Copyright (c) 2000, 2019, 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>
mysql> show variables like '%password%';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> alter user root@'localhost' identified by '1';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

mysql> alter user root@'localhost' identified by 'MySQL1234!';
Query OK, 0 rows affected (0.01 sec)

mysql> show variables like 'validate%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.00 sec)

mysql> set @@global.validate_password_policy=1,@@global.validate_password_number_count=0,@@global.validate_password_special_char_count=0,@@global.validate_password_mixed_case_count=0,@@global.validate_password_length=1;
Query OK, 0 rows affected (0.01 sec)

mysql> show variables like 'validate%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 1 |
| validate_password_mixed_case_count | 0 |
| validate_password_number_count | 0 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 0 |
+--------------------------------------+--------+
7 rows in set (0.00 sec)

mysql> alter user root@'localhost' identified by '1';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
[root@master ~]# mysql_config_editor set --login-path=client --user=root --host=localhost --port=3306 --password
Enter password:
[root@master ~]# ls -lrth
-rw-------. 1 root root 140 Dec 9 20:36 .mylogin.cnf
[root@master ~]# mysql_config_editor print --all
[client]
user = root
password = *****
host = localhost
port = 3306
[root@master ~]# mysql_config_editor print --login-path=client
[client]
user = root
password = *****
host = localhost
port = 3306
[root@master ~]# mysql_config_editor remove --login-path=client
[root@master ~]# mysql_config_editor print --all
[root@master ~]#

[root@master ~]# mysql_config_editor print --all=false
[client]
user = root
password = *****
host = localhost
port = 3306
[root@master ~]# mysql_config_editor set --login-path=haha --user=root --host=localhost --port=3306 --password
Enter password:
[root@master ~]# mysql_config_editor print --all
[client]
user = root
password = *****
host = localhost
port = 3306
[haha]
user = root
password = *****
host = localhost
port = 3306
[root@master ~]# mysql --login-path=haha
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.26 MySQL Community Server (GPL)

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

导出结果集到文件

1
2
mysql> select * from test.jobs into outfile '/tmp/db_test_tb_jobs';
Query OK, 19 rows affected (0.03 sec)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
mysql> pager cat >> /tmp/db_test_tb_jobs;
PAGER set to 'cat >> /tmp/db_test_tb_jobs'
mysql> select * from test.jobs;
19 rows in set (0.00 sec)

mysql> nopager;
PAGER set to stdout
mysql> system cat /tmp/db_test_tb_jobs;
AC_ACCOUNT Public Accountant 4200 9000
AC_MGR Accounting Manager 8200 16000
AD_ASST Administration Assistant 3000 6000
AD_PRES President 20080 40000
AD_VP Administration Vice President 15000 30000

+------------+---------------------------------+------------+------------+
| JOB_ID | JOB_TITLE | MIN_SALARY | MAX_SALARY |
+------------+---------------------------------+------------+------------+
| AC_ACCOUNT | Public Accountant | 4200 | 9000 |
| AC_MGR | Accounting Manager | 8200 | 16000 |
| AD_ASST | Administration Assistant | 3000 | 6000 |
| AD_PRES | President | 20080 | 40000 |
| AD_VP | Administration Vice President | 15000 | 30000 |
+------------+---------------------------------+------------+------------+
mysql>