安装前提
1、使用pkg安装mysql有个前提FreeBSD版本12.2及以上。
2、内存最好是8GB及以上
安装
$ pkg search mysql
……
mysql80-client-8.0.35 Multithreaded SQL database (client)
mysql80-server-8.0.35 Multithreaded SQL database (server)
mysql81-client-8.1.0 Multithreaded SQL database (client)
mysql81-server-8.1.0 Multithreaded SQL database (server)
……
$ sudo pkg install mysql81-server mysql81-client
$ service mysql-server status
Cannot 'status' mysql. Set mysql_enable to YES in /etc/rc.conf or use 'onestatus' instead of 'status'.
设置开机自启动
$ sudo sysrc mysql_enable=yes
$ service mysql-server status
mysql is not running.
启动服务
$ sudo service mysql-server start #---这里会卡很长时间,并且会启动失败,如果重启系统(reboot)会开机自启动成功
$ sudo service mysql-server status
mysql is running as pid 86312.
验证监听端口
$ sockstat -46l|grep 3306 #---如果没有默认的my.cnf则可能bind到*上
mysql mysqld 86312 29 tcp46 *:33060 *:*
mysql mysqld 86312 31 tcp46 *:3306 *:*
$ sockstat -46l #---有默认的my.cnf则会bind到127.0.0.1,需要修改
USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
mysql mysqld 98355 18 tcp46 *:33060 *:*
mysql mysqld 98355 31 tcp4 127.0.0.1:3306 *:*
$ vi /usr/local/etc/mysql/my.cnf
bind-address = 192.168.11.199
#bind-address = 127.0.0.1
执行安全设置及修改root密码
$ sudo mysql_secure_installation
1、启用密码策略工具
2、修改root密码
3、禁止root远程登录
4、删除test数据库
5、删除匿名登录用户
启动 MySQL 服务:sudo service mysql-server start
停止 MySQL 服务:sudo service mysql-server stop
重启 MySQL 服务:sudo service mysql-server restart
加载 MySQL 配置:sudo service mysql-server reload
查看MySQL版本
mysqladmin -u root -p version
Enter password:
mysqladmin Ver 8.0.33 for FreeBSD14.0 on amd64 (Source distribution)
Copyright (c) 2000, 2023, 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.
Server version 8.0.33
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /tmp/mysql.sock
Uptime: 45 min 0 sec文章来源:https://www.toymoban.com/news/detail-797038.html
Threads: 2 Questions: 33 Slow queries: 0 Opens: 154 Flush tables: 3 Open tables: 73 Queries per second avg: 0.012文章来源地址https://www.toymoban.com/news/detail-797038.html
到了这里,关于FreeBSD上安装mysql数据库的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!