/├──root/│└──.mysql_secret# MySQL 5.7 root 密码文件└──usr/└──ports/└──databases/├──mysql55-server/# MySQL 5.5 Server Port├──mysql56-server/# MySQL 5.6 Server Port└──mysql57-server/# MySQL 5.7 Server Port
# git clone https://github.com/freebsd/freebsd-ports /usr/ports # 克隆 FreeBSD ports 仓库到 /usr/ports
# cd /usr/ports && git checkout 9f0ff92f6deaa2187cdb33a27f5aebbdd2c0d71d # 进入 ports 目录并切换到 MySQL 5.5 的最后提交
# cd /usr/ports/databases/mysql55-server/ && make install clean # 进入 MySQL 5.5 Server 目录并编译安装,同时清理临时文件
# git clone https://github.com/freebsd/freebsd-ports /usr/ports # 克隆 FreeBSD ports 仓库到 /usr/ports
# cd /usr/ports && git checkout 7cab9ba40f8fd39656074d22b474ed7408e1368e # 进入 ports 目录并切换到 MySQL 5.6 的最后提交
# cd /usr/ports/databases/mysql56-server/ && make install clean # 进入 MySQL 5.6 Server 目录并编译安装,同时清理临时文件
# sysrc mysql_enable="YES" # 设置 MySQL 服务开机自动启动
# service mysql-server start # 启动 MySQL 服务实例
# mysql_secure_installation
# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
... skipping.
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] n
... skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n]
... Success!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...
# mysql -u root -p
# mysql -u root -p # 登录到 MySQL
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 12
Server version: 5.6.51 Source distribution
Copyright (c) 2000, 2021, 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; -- 列出当前 MySQL 实例中的所有数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
# git clone https://github.com/freebsd/freebsd-ports /usr/ports # 克隆 FreeBSD ports 仓库到 /usr/ports
# cd /usr/ports && git checkout 69e2e87fa56b54e267429b326f7f6188a7baaa71 # 进入 ports 目录并切换到指定的最后的 MySQL 5.7 提交
# cd /usr/ports/databases/mysql57-server/ && make install clean # 进入 MySQL 5.7 Server 目录并编译安装,同时清理临时文件
# sysrc mysql_enable=YES # 设置 MySQL 服务开机自启
# service mysql-server start # 启动 MySQL 服务
# sysrc mysql_enable=YES # 设置 MySQL 服务开机自启
mysql_enable: -> YES
# service mysql-server start # 启动 MySQL 服务
Starting mysql.
# cat /root/.mysql_secret # 打印 MySQL root 的密码
# Password set for user 'root@localhost' at 2021-12-13 00:21:02
q(<p2ZZ>lX/:
# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.36-log
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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.
root@localhost [(none)]> show databases; -- 列出当前 MySQL 实例中的所有数据库
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
-- 注意:请使用 ALTER USER 语句修改密码,例如:ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
root@localhost [(none)]>
# mysql -u root -p # 使用 root 用户登录 MySQL,提示输入密码
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.36-log Source distribution
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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.
root@localhost [(none)]> show databases; -- 列出当前 MySQL 实例中的所有数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)