MySQL
Подготовка клетки для MySQL
Дополнительная информация о создании клеток (jail) находится в с статье Qjail.
Создание отдельной файловой системы для клетки с MySQL в ZFS:
# zfs create zroot/usr/jails/mysql
Создание клетки c именем "mysql" и IPv4-адресом "192.168.0.103", её запуск и вход в консоль:
# qjail create -4 192.168.0.103 mysql # qjail start mysql # qjail console mysql
Установка databases/mysql91-server
MySQL - это очень быстрый, многопоточный, многопользовательский и надежный сервер баз данных SQL.
Подробная информация на сайте https://www.mysql.com/
Установка из пакета (предварительная установка менеджера пакетов PKG не требуется, дополнительная информация о котором в статье PKG)::
# pkg install mysql91-server
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 27 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
brotli: 1.1.0,1
curl: 8.12.1
cyrus-sasl: 2.1.28_5
groff: 1.23.0_4
hidapi: 0.14.0
[пропущен список пакетов для установки]
Number of packages to be installed: 27
The process will require 470 MiB more space.
72 MiB to be downloaded.
Proceed with this action? [y/N]: y
[1/27] Fetching indexinfo-0.3.1_1.pkg: 100% 6 KiB 6.0kB/s 00:01
[2/27] Fetching cyrus-sasl-2.1.28_5.pkg: 100% 1 MiB 1.1MB/s 00:01
[3/27] Fetching libcjson-1.7.18_2.pkg: 100% 39 KiB 39.5kB/s 00:01
[4/27] Fetching libnghttp2-1.65.0.pkg: 100% 136 KiB 139.4kB/s 00:01
[5/27] Fetching mysql91-client-9.1.0_1.pkg: 100% 6 MiB 3.1MB/s 00:02
[пропущен список скачиваемых пакетов]
Checking integrity... done (0 conflicting)
[1/27] Installing brotli-1.1.0,1...
[1/27] Extracting brotli-1.1.0,1: 100%
[2/27] Installing cyrus-sasl-2.1.28_5...
*** Added group `cyrus' (id 60)
*** Added user `cyrus' (id 60)
[2/27] Extracting cyrus-sasl-2.1.28_5: 100%
[3/27] Installing icu-76.1,1...
[3/27] Extracting icu-76.1,1: 100%
[4/27] Installing indexinfo-0.3.1_1...
[4/27] Extracting indexinfo-0.3.1_1: 100%
[5/27] Installing libcjson-1.7.18_2...
[5/27] Extracting libcjson-1.7.18_2: 100%
[пропущен список устанавливаемых пакетов]
[27/27] Installing mysql91-server-9.1.0_1...
===> Creating groups
Creating group 'mysql' with gid '88'
===> Creating users
Creating user 'mysql' with uid '88'
===> Creating homedir(s)
[27/27] Extracting mysql91-server-9.1.0_1: 100%
=====
Message from cyrus-sasl-2.1.28_5:
--
You can use sasldb2 for authentication, to add users use:
saslpasswd2 -c username
If you want to enable SMTP AUTH with the system Sendmail, read
Sendmail.README
NOTE: This port has been compiled with a default pwcheck_method of
auxprop. If you want to authenticate your user by /etc/passwd,
PAM or LDAP, install ports/security/cyrus-sasl2-saslauthd and
set sasl_pwcheck_method to saslauthd after installing the
Cyrus-IMAPd 2.X port. You should also check the
/usr/local/lib/sasl2/*.conf files for the correct
pwcheck_method.
If you want to use GSSAPI mechanism, install
ports/security/cyrus-sasl2-gssapi.
If you want to use SRP mechanism, install
ports/security/cyrus-sasl2-srp.
If you want to use LDAP auxprop plugin, install
ports/security/cyrus-sasl2-ldapdb.
=====
Message from openldap26-client-2.6.9_1:
--
The OpenLDAP client package has been successfully installed.
Edit
/usr/local/etc/openldap/ldap.conf
to change the system-wide client defaults.
Try `man ldap.conf' and visit the OpenLDAP FAQ-O-Matic at
http://www.OpenLDAP.org/faq/index.cgi?file=3
for more information.
=====
Message from groff-1.23.0_4:
--
In order to be able to use the html driver, you need to install the following
packages:
- ghostscript
- netpbm
--
===> NOTICE:
The groff port currently does not have a maintainer. As a result, it is
more likely to have unresolved issues, not be up-to-date, or even be removed in
the future. To volunteer to maintain this port, please create an issue at:
https://bugs.freebsd.org/bugzilla
More information about port maintainership is available at:
https://docs.freebsd.org/en/articles/contributing/#ports-contributing
=====
Message from mysql91-client-9.1.0_1:
--
This is the mysql CLIENT without the server.
for complete server and client, please install databases/mysql91-server
=====
Message from mysql91-server-9.1.0_1:
--
There is no initial password for first time use of 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.
Настройка и запуск databases/mysql91-server
Копирование файла настроек:
# cp /usr/local/etc/mysql/my.cnf.sample /usr/local/etc/mysql/my.cnf
Установка автозапуска MySQL в /etc/rc.conf:
# sysrc mysql_enable="YES" mysql_enable: -> YES
Запуск MySQL:
# service mysql-server start Starting mysql.
Проверка MySQL:
# sockstat -l | grep mysql mysql mysqld 2637 29 tcp46 *:33060 *:* mysql mysqld 2637 30 stream /tmp/mysqlx.sock mysql mysqld 2637 32 tcp4 127.0.0.1:3306 *:* mysql mysqld 2637 34 stream /tmp/mysql.sock
Установка пароля для пользователя "root" (начальный пароль отсутствует) и применение изменений:
# mysql -u root -p > alter user 'root'@'localhost' identified by 'новый_пароль_root'; Query OK, 0 rows affected (0.02 sec) > flush privileges; Query OK, 0 rows affected (0.01 sec)
Возможные проблемы с databases/mysql91-server
MySQL отказывается стартовать после установки из пакета с "нуля".
# service mysql-server start /usr/local/etc/rc.d/mysql-server: WARNING: failed precmd routine for mysql
Проблема связана с установленными при установке правами на папки MySQL.
Проверка прав на папки MySQL:
# cd /var/db # ls -l | grep mysql drwxr-xr-x 2 mysql mysql 4 Apr 13 10:49 mysql drwxr-xr-x 2 root wheel 2 Apr 13 10:48 mysql_secure drwxr-xr-x 2 root wheel 2 Apr 13 10:48 mysql_tmpdir
Установка владельца папок и очистка содержимого папки mysql:
# chown mysql:mysql mysql_secure mysql_tmpdir # rm mysql/*
Повторная проверка прав на папки MySQL:
# ls -l | grep mysql drwxr-xr-x 2 mysql mysql 2 Apr 13 10:58 mysql drwxr-xr-x 2 mysql mysql 2 Apr 13 10:48 mysql_secure drwxr-xr-x 2 mysql mysql 2 Apr 13 10:48 mysql_tmpdir
Запуск MySQL:
# service mysql-server start Starting mysql.
Резервное копирование и восстановление баз данных
Резервное копирование базы данных:
# mysqldump -u <имя> -p --set-gtid-purged=OFF <имя_базы> > ~/<имя_базы>_backup.sql
Создание базы данных:
# mysql -u <имя> -p > create database <имя_базы>; Query OK, 1 row affected (0.00 sec)
Восстановление базы данных:
# mysql -u <имя> -p <имя_базы> < ~/<имя_базы>_backup.sql