第二十八章 DragonFlyBSD
第四节 MySQL 5.X

mysql 5.5(请参考5.6)/5.6

安装

pkg、ports 安装二选一
1
# pkg install mysql56-server
2
# 或者
3
# cd /usr/ports/databases/mysql56-server/ && make install clean
Copied!

启动服务

1
# sysrc mysql_enable=YES
2
# service mysql-server start
Copied!

配置

1
# mysql_secure_installation
Copied!
输出:
1
[email protected]:~ # mysql_secure_installation
2
3
4
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
5
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
6
7
In order to log into MySQL to secure it, we'll need the current
8
password for the root user. If you've just installed MySQL, and
9
you haven't set the root password yet, the password will be blank,
10
so you should just press enter here.
11
12
13
Enter current password for root (enter for none):
14
OK, successfully used password, moving on...
15
16
Setting the root password ensures that nobody can log into the MySQL
17
root user without the proper authorisation.
18
19
Set root password? [Y/n] y
20
New password:
21
Re-enter new password:
22
Password updated successfully!
23
Reloading privilege tables..
24
... Success!
25
26
27
By default, a MySQL installation has an anonymous user, allowing anyone
28
to log into MySQL without having to have a user account created for
29
them. This is intended only for testing, and to make the installation
30
go a bit smoother. You should remove them before moving into a
31
production environment.
32
33
Remove anonymous users? [Y/n] y
34
... Success!
35
36
Normally, root should only be allowed to connect from 'localhost'. This
37
ensures that someone cannot guess at the root password from the network.
38
39
Disallow root login remotely? [Y/n] n
40
... skipping.
41
42
By default, MySQL comes with a database named 'test' that anyone can
43
access. This is also intended only for testing, and should be removed
44
before moving into a production environment.
45
46
Remove test database and access to it? [Y/n] n
47
... skipping.
48
49
Reloading the privilege tables will ensure that all changes made so far
50
will take effect immediately.
51
52
Reload privilege tables now? [Y/n]
53
... Success!
54
55
56
57
58
All done! If you've completed all of the above steps, your MySQL
59
installation should now be secure.
60
61
Thanks for using MySQL!
62
63
64
Cleaning up...
Copied!

使用

登录
1
# mysql -u root -p
Copied!
示例输出
1
[email protected]:~ # mysql -u root -p
2
Enter password:
3
Welcome to the MySQL monitor. Commands end with ; or g.
4
Your MySQL connection id is 12
5
Server version: 5.6.51 Source distribution
6
7
Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
8
9
Oracle is a registered trademark of Oracle Corporation and/or its
10
affiliates. Other names may be trademarks of their respective
11
owners.
12
13
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
14
15
mysql> show databases;
16
+--------------------+
17
| Database |
18
+--------------------+
19
| information_schema |
20
| mysql |
21
| performance_schema |
22
| test |
23
+--------------------+
24
4 rows in set (0.00 sec)
25
26
mysql>
Copied!

mysql 5.7

注意:如果是从旧版本升级,请先执行mysql_upgrade

安装

以下二选一
1
# pkg install mysql57-server
2
# 或
3
# cd /usr/ports/databases/mysql57-server/ && make install clean
Copied!

启动服务

1
# sysrc mysql_enable=YES
2
# service mysql-server start
Copied!
示例输出(可以看到密码在/root/.mysql_secret文件夹下,是q(<p2ZZ>lX/:
1
[email protected]:~ # sysrc mysql_enable=YES
2
mysql_enable: -> YES
3
[email protected]:~ # service mysql-server start
4
Starting mysql.
5
[email protected]:~ # cat /root/.mysql_secret
6
# Password set for user '[email protected]' at 2021-12-13 00:21:02
7
q(<p2ZZ>lX/:
Copied!

尝试登录

登录出现报错,提示需要修改密码。
1
[email protected]:~ # mysql -u root -p
2
Enter password:
3
Welcome to the MySQL monitor. Commands end with ; or g.
4
Your MySQL connection id is 2
5
Server version: 5.7.36-log
6
7
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
8
9
Oracle is a registered trademark of Oracle Corporation and/or its
10
affiliates. Other names may be trademarks of their respective
11
owners.
12
13
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
14
15
[email protected] [(none)]> show databases;
16
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
17
Copied!

修改密码

将现在的密码修改为your_new_password,然后刷新权限。
1
[email protected] [(none)]> SET PASSWORD = PASSWORD('your_new_password');
2
Query OK, 0 rows affected, 1 warning (0.00 sec)
3
[email protected] [(none)]> flush privileges;
4
Query OK, 0 rows affected (0.00 sec)
Copied!
正常登录
1
[email protected]:~ # mysql -u root -p
2
Enter password:
3
Welcome to the MySQL monitor. Commands end with ; or g.
4
Your MySQL connection id is 3
5
Server version: 5.7.36-log Source distribution
6
7
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
8
9
Oracle is a registered trademark of Oracle Corporation and/or its
10
affiliates. Other names may be trademarks of their respective
11
owners.
12
13
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
14
15
[email protected] [(none)]> show databases;
16
+--------------------+
17
| Database |
18
+--------------------+
19
| information_schema |
20
| mysql |
21
| performance_schema |
22
| sys |
23
+--------------------+
24
4 rows in set (0.00 sec)
25
26
Copied!
最近更新 1mo ago