第 17.5 节 MySQL 8.X
安装
MySQL 8.0 LTS
安装:
# pkg install mysql80-server
或编译安装:
# cd /usr/ports/databases/mysql80-server/
# make install clean
MySQL 8.4 LTS
安装:
# pkg install mysql84-server
或编译安装:
# cd /usr/ports/databases/mysql84-server/
# make install clean
查看安装后说明(8.0 类似):
root@ykla:~ # pkg info -D mysql84-server
mysql84-server-8.4.3_1:
On install:
There is no initial password for first time use of MySQL. # 即无密码
首次使用 MySQL 时没有初始密码。# 即无密码
Keep in mind to reset it to a secure password.
记得将其重置为一个安全的密码。
MySQL 8.4 has a default /usr/local/etc/mysql/my.cnf,
remember to replace it with your own
or set `mysql_optfile="$YOUR_CNF_FILE` in rc.conf.
MySQL 8.4 有一个默认的 /usr/local/etc/mysql/my.cnf,
记得用你自己的文件替换它,
或者在 rc.conf 中设置 `mysql_optfile="$YOUR_CNF_FILE`。
On upgrade:
As of MySQL 8.0.16, the MySQL server performs the upgrade tasks previously
handled by mysql_upgrade. Consequently, mysql_upgrade is unneeded and is
deprecated as of that version, and will be removed in a future MySQL version.
从 MySQL 8.0.16 开始,MySQL 服务器执行以前由 mysql_upgrade 处理的升级任务。
因此,mysql_upgrade 不再需要,并且从该版本开始被弃用,
将在未来的 MySQL 版本中移除。
Because mysql_upgrade no longer performs upgrade tasks,
it exits with status 0 unconditionally.
因为 mysql_upgrade 不再执行升级任务,
它无条件地以状态 0 退出。
启动服务
# service mysql-server enable
mysql enabled in /etc/rc.conf
# service mysql-server start
Starting mysql.
登录
根据安装后说明,mysql 8.0、8.4 默认密码为空,直接回车即可。
root@ykla:~ # mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 8
Server version: 8.0.27 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)]>
修改密码
设置数据库的 root 密码为 z
,然后刷新权限,随后退出。
root@localhost [(none)]> alter user 'root'@'localhost' identified by 'z';
Query OK, 0 rows affected (0.02 sec)
root@localhost [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
root@localhost [(none)]> quit;
Bye
重新登录:
root@ykla:~ # mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 9
Server version: 8.0.27 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;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
root@localhost [(none)]>
配置文件
默认的配置文件模板位于 /usr/local/etc/mysql/my.cnf.sample
,默认的配置文件理论上位于 /usr/local/etc/mysql/my.cnf
(但默认为空)。
可以这样:
# cp /usr/local/etc/mysql/my.cnf.sample /usr/local/etc/mysql/my.cnf
然后按需修改 /usr/local/etc/mysql/my.cnf
即可。
在 /etc/rc.conf
中,写入
mysql_optfile="/abc/xyz.cnf"
可以改变配置文件路径。
最后更新于