当前位置: 首页 >数据库 > FreeBSD 安装 MySQL 5.X

FreeBSD 安装 MySQL 5.X

mysql 5.5(请参考5.6)/5.6

安装

pkg、ports 安装二选一

# pkg install mysql56-server# 或者# cd /usr/ports/databases/mysql56-server/ && make install clean

启动服务

# sysrc mysql_enable=YES# service mysql-server start

配置

# mysql_secure_installation

输出:

root@ykla:~ # mysql_secure_installationNOTE: 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 currentpassword for the root user.  If you've just installed MySQL, andyou 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 MySQLroot user without the proper authorisation.Set root password? [Y/n] yNew password: Re-enter new password: Password updated successfully!Reloading privilege tables.. ... Success!By default, a MySQL installation has an anonymous user, allowing anyoneto log into MySQL without having to have a user account created forthem.  This is intended only for testing, and to make the installationgo a bit smoother.  You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] y ... Success!Normally, root should only be allowed to connect from 'localhost'.  Thisensures 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 canaccess.  This is also intended only for testing, and should be removedbefore 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 farwill take effect immediately.Reload privilege tables now? [Y/n]  ... Success!All done!  If you've completed all of the above steps, your MySQLinstallation should now be secure.Thanks for using MySQL!Cleaning up...

使用

登录# mysql -u root -p示例输出root@ykla:~ # mysql -u root -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or g.Your MySQL connection id is 12Server version: 5.6.51 Source distributionCopyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.mysql> show databases;+--------------------+| Database|+--------------------+| information_schema || mysql  || performance_schema || test|+--------------------+4 rows in set (0.00 sec)mysql> 

mysql 5.7

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

安装

以下二选一

# pkg install mysql57-server# 或# cd /usr/ports/databases/mysql57-server/ && make install clean

启动服务

# sysrc mysql_enable=YES# service mysql-server start

示例输出(可以看到密码在/root/.mysql_secret文件夹下,是q(<p2ZZ>lX/:

root@ykla:~ # sysrc mysql_enable=YESmysql_enable:  -> YESroot@ykla:~ # service mysql-server startStarting mysql.root@ykla:~ # cat /root/.mysql_secret# Password set for user 'root@localhost' at 2021-12-13 00:21:02 q(<p2ZZ>lX/:root@ykla:~ # 

尝试登录

登录出现报错,提示需要修改密码。

root@ykla:~ # mysql -u root -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or g.Your MySQL connection id is 2Server version: 5.7.36-logCopyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.root@localhost [(none)]> show databases;ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.root@localhost [(none)]> 

修改密码

将现在的密码修改为your_new_password,然后刷新权限。

root@localhost [(none)]> SET PASSWORD = PASSWORD('your_new_password');Query OK, 0 rows affected, 1 waing (0.00 sec)root@localhost [(none)]> flush privileges;Query OK, 0 rows affected (0.00 sec)

正常登录

root@ykla:~ # mysql -u root -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or g.Your MySQL connection id is 3Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners. 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.00 sec)root@localhost [(none)]> 

作者:FreeBSD中文社区
来源链接:https://www.cnblogs.com/FreeBSD-CN/p/15751248.html

版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。





本文链接:https://www.javaclub.cn/database/117928.html

标签:MySQL升级
分享给朋友:

“FreeBSD 安装 MySQL 5.X” 的相关文章

sql递归查询 2022年05月17日 21:40:33
mysql查询数据库表的数据行数 2022年06月12日 12:49:23
MYSQL查询大于某个时间的数据 2022年06月12日 14:04:47
查询mysql中user表 2022年06月12日 18:08:24
关于mysql查询时间范围的问题 2022年06月12日 21:19:01
MySQL查询表中的数据是否存在 2022年06月13日 13:46:57
MySQL查询指定行的记录 2022年06月14日 06:02:58