Ferramentas do usuário

Ferramentas do site


instalacao_do_bd_mysql

Procedimento para instalar o BD MySQL no FreeBSD

1 - Vamos para a instalação do BD mysql:

root@glpi:/usr/local/etc # pkg search mysql

mysql55-server-5.5.60          Multithreaded SQL database (server)
mysql56-server-5.6.41          Multithreaded SQL database (server)
mysql57-server-5.7.23_1        Multithreaded SQL database (server)
mysql80-server-8.0.12          Multithreaded SQL database (server)

2 - Encontre as linha a linha a qual diz respeito a instalação do serviço de Banco de Dados mysql:

- No meu caso encontrei quatro versões, vou usar a penúltima, versão 5.7:

root@glpi:/usr/local/etc # pkg install mysql57-server-5.7.23_1

3 - Após o termino da instalação do mysql, vamos configurar o serviço no /etc/rc.conf e estartar o serviço. Se a instalação estiver sido correta, ele deve iniciar normalmente:

root@glpi:/usr/local/etc # /usr/local/etc/rc.d/mysql-server enable

– Foi acrescentado a linha que inicia o serviço na hora do boot mysql_enable=“YES”, agora vamos levantar o serviço.

root@glpi:/usr/local/etc # /usr/local/etc/rc.d/mysql-server start
Starting mysql.

– Agora vamos ver se o serviço está rodando:

root@glpi:/usr/local/etc # sockstat -4l
USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS
mysql    mysqld     83282 22 tcp4   127.0.0.1:3306        *:*
www      httpd      80469 4  tcp4   *:80                  *:*
www      httpd      80468 4  tcp4   *:80                  *:*
www      httpd      80467 4  tcp4   *:80                  *:*
www      httpd      80466 4  tcp4   *:80                  *:*
www      httpd      80465 4  tcp4   *:80                  *:*
www      httpd      80464 4  tcp4   *:80                  *:*
www      httpd      80463 4  tcp4   *:80                  *:*
root     httpd      80462 4  tcp4   *:80                  *:*
root     sendmail   585   3  tcp4   127.0.0.1:25          *:*
root     sshd       557   4  tcp4   *:22                  *:*
root     syslogd    355   7  udp4   *:514                 *:*
root@glpi:/usr/local/etc #

– Como podemos ver, o apache e o mysql já estão funcionando:

– O mysql está rodando no endereço 127.0.0.1. Teremos que alterar para o endereço ip da máquina, vamos ter que editar o arquivo /usr/local/etc/mysql/my.cnf

root@glpi:/usr/local/etc/mysql # ee my.cnf
^[ (escape) menu  ^y search prompt  ^k delete line   ^p prev li   ^g prev page
^o ascii code     ^x search         ^l undelete line ^n next li   ^v next page
^u end of file    ^a begin of line  ^w delete word   ^b back 1 char
^t top of text    ^e end of line    ^r restore word  ^f forward 1 char
^c command        ^d delete char    ^j undelete char ^z next word
=====line 15 col 46 lines from top 15 =========================================
# $FreeBSD: branches/2018Q3/databases/mysql57-server/files/my.cnf.sample.in 414707 2016-05-06 14:39:59Z riggs $

[client]
port                            = 3306
socket                          = /tmp/mysql.sock

[mysql]
prompt                          = \u@\h [\d]>\_
no_auto_rehash

– Encontre a linha “bind-address” adicione o endereço IP e reinicie o serviço mysql:

bind-address                    = 172.19.1.123

– Vamos restartar o serviço e verificar se está rodando:

root@glpi:/usr/local/etc/mysql # service mysql-server restart
Starting mysql.

root@glpi:/usr/local/etc/mysql # sockstat -4
USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS
mysql    mysqld     86585 22 tcp4   172.19.1.123:3306     *:*
www      httpd      83664 4  tcp4   *:80                  *:*
www      httpd      83660 4  tcp4   *:80                  *:*
www      httpd      83659 4  tcp4   *:80                  *:*
www      httpd      83658 4  tcp4   *:80                  *:*
www      httpd      83657 4  tcp4   *:80                  *:*
www      httpd      83656 4  tcp4   *:80                  *:*
root     httpd      83655 4  tcp4   *:80                  *:*
dhiemeson sshd      80149 3  tcp4   172.19.1.123:22       10.10.10.117:63198
root     sshd       80146 3  tcp4   172.19.1.123:22       10.10.10.117:63198
root     sendmail   585   3  tcp4   127.0.0.1:25          *:*
root     sshd       557   4  tcp4   *:22                  *:*
root     syslogd    355   7  udp4   *:514                 *:*

4 - Vamos preparar a configuração padrão do MySQL. Precisamos atribuir uma senha para a conta root do mysql, usaremos o comando "mysql_secure_installation", ele vai nos dar algumas opções como:

root@glpi:/usr/local/etc/mysql # mysql_secure_installation

– Nas opções que virão a seguir, siga essas instruções (resumo):

1 - Change the password for root ? (Alterar a senha do root?) ((Press y|Y for Yes, any other key for No) :  
2 - Remove anonymous users? (Remover usuário anônimos?) (Press y|Y for Yes, any other key for No) : y
3 - Disallow root login remotely? (Desabilitar login remoto?) (Press y|Y for Yes, any other key for No) :
4 - Disallow root login remotely? (Desabilitar login de root remoto?)(Press y|Y for Yes, any other key for No) :
5 - Remove test database and access to it? (Remover banco de dados de testes e acesso a eles?) (Press y|Y for Yes, any other key for No) : y
6 - Reload privilege tables now? (Recarregue as tabelas de privilégios agora))(Press y|Y for Yes, any other key for No) : y

— Passa a posso completo —

root@glpi:/usr/local/etc/mysql # mysql_secure_installation
mysql_secure_installation: [ERROR] unknown variable 'prompt=\u@\h [\d]>\_'

Securing the MySQL server deployment.

Connecting to MySQL server using password in '/root/.mysql_secret'

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No:
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y
New password:

Re-enter new password:
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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) :

 ... 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? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!


root@glpi:/usr/local/etc/mysql #

5 - Vamos tentar acessar com o root agora:

root@glpi:/usr/local/etc/mysql # mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.23-log

Copyright (c) 2000, 2018, 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.

root@localhost [(none)]>

– Feito isso, se você conseguiu, está tudo certo. Agora crie seu banco e continue o trabalho:


Deixe sua contribuição

Insira seu comentário:
 
instalacao_do_bd_mysql.txt · Última modificação: 2023/04/18 23:15 por dhiemeson.nascimento