Gerenciamento e uso do banco de dados MariaDB
MariaDB é um sistema de gerenciamento de banco de dados relacional de código aberto, derivado do MySQL, com alta performance, escalabilidade e confiabilidade. O ServBay acompanha MariaDB, e este artigo detalhará como gerenciar e usar o banco de dados MariaDB no ServBay, incluindo instalação, configuração, backup, restauração e otimização de desempenho.
Instalação e configuração do MariaDB
O ServBay vem com o MariaDB instalado, você só precisa garantir que ele esteja em execução e realizar as configurações necessárias.
Inicializando e gerenciando o serviço MariaDB
Você pode gerenciar o serviço MariaDB através da plataforma de gerenciamento do ServBay ou utilizando a ferramenta de linha de comando servbayctl
.
Usando a plataforma de gerenciamento do ServBay
- Abra a plataforma de gerenciamento do ServBay.
- Navegue até "Serviços".
- Encontre o serviço MariaDB e realize a operação de iniciar, parar ou reiniciar.
Usando a ferramenta de linha de comando servbayctl
# Iniciar o serviço MariaDB
servbayctl start mariadb 11.3
# Parar o serviço MariaDB
servbayctl stop mariadb 11.3
# Reiniciar o serviço MariaDB
servbayctl restart mariadb 11.3
2
3
4
5
6
7
8
Configurando o MariaDB
O arquivo de configuração padrão do MariaDB no ServBay já está otimizado. Se o usuário precisar modificar o arquivo de configuração por conta própria, ele pode ser encontrado no seguinte caminho:
/Applications/ServBay/etc/mariadb/11.3/my.cnf
Dependendo da versão do MariaDB, o arquivo de configuração estará em diferentes pastas.
Conectando ao MariaDB
Você pode conectar ao MariaDB usando a ferramenta de linha de comando mysql
ou ferramentas gráficas como phpMyAdmin e Adminer.
Conectando usando a linha de comando
Usando conexão TCP/IP:
bashmysql -u your_username -p -h localhost -P 3306
1Usando conexão via Socket:
bashmysql -u your_username -p -S /Applications/ServBay/tmp/mysql.sock
1
Conectando usando phpMyAdmin e Adminer
O ServBay já inclui phpMyAdmin e Adminer, você pode acessá-los da seguinte maneira:
- URL de acesso:
https://servbay.host
Nesta página, você encontrará as entradas para o phpMyAdmin e Adminer; use o nome de usuário e senha obtidos a partir do painel de gerenciamento do ServBay para fazer login.
Gerenciamento de banco de dados
Criando banco de dados e usuários
Criando banco de dados:
sqlCREATE DATABASE mydatabase;
1Criando usuário e concedendo permissões:
sqlCREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON mydatabase.* TO 'your_username'@'localhost'; FLUSH PRIVILEGES;
1
2
3
Backup e recuperação
Fazendo backup do banco de dados
Recomenda-se armazenar os arquivos de backup no seguinte diretório:
/Applications/ServBay/backup/mariadb
Use a ferramenta mysqldump
para fazer backup do banco de dados:
mysqldump -u your_username -p mydatabase > /Applications/ServBay/backup/mariadb/mydatabase.sql
Recuperando o banco de dados
Use a ferramenta mysql
para restaurar o banco de dados:
mysql -u your_username -p mydatabase < /Applications/ServBay/backup/mariadb/mydatabase.sql
Otimização de desempenho
O MariaDB oferece várias opções de otimização de desempenho. Abaixo estão alguns métodos comuns de otimização.
Otimização de índices
Garanta que as colunas usadas com frequência em consultas tenham índices. Por exemplo:
CREATE INDEX idx_column_name ON your_table_name(column_name);
Otimização de consultas
Use o comando EXPLAIN
para analisar o desempenho das consultas e faça as otimizações necessárias. Por exemplo:
EXPLAIN SELECT * FROM your_table_name WHERE column_name = 'value';
Otimização de configuração
Ajuste os parâmetros no arquivo de configuração para melhorar o desempenho. Por exemplo, ajuste o tamanho do pool de buffers:
[mysqld]
innodb_buffer_pool_size = 1G
2
Gerenciamento de segurança
Garantir a segurança do banco de dados é muito importante. Aqui estão algumas recomendações de gerenciamento de segurança.
Configurando senhas fortes
Configure senhas fortes para todos os usuários do banco de dados:
SET PASSWORD FOR 'your_username'@'localhost' = PASSWORD('your_new_password');
Backup regular
Faça backups regulares do banco de dados para evitar perda de dados.
Restrição de acesso
Restrinja os privilégios dos usuários do banco de dados, concedendo apenas as permissões necessárias:
REVOKE ALL PRIVILEGES ON *.* FROM 'your_username'@'localhost';
GRANT SELECT, INSERT, UPDATE ON mydatabase.* TO 'your_username'@'localhost';
2
Problemas comuns e soluções
Não é possível conectar ao MariaDB
Verifique se o MariaDB está em execução:
bashservbayctl status mariadb 11.3
1Verifique as configurações do firewall: Certifique-se de que o firewall permite a passagem da porta do MariaDB (porta padrão 3306).
Problemas de permissão
Verifique as permissões do usuário:
sqlSHOW GRANTS FOR 'your_username'@'localhost';
1Conceda as permissões necessárias:
sqlGRANT ALL PRIVILEGES ON mydatabase.* TO 'your_username'@'localhost'; FLUSH PRIVILEGES;
1
2
Conclusão
MariaDB é um sistema de gerenciamento de banco de dados poderoso e flexível. O ServBay acompanha o MariaDB, tornando o gerenciamento e uso do banco de dados mais conveniente. Através deste artigo, você pode facilmente realizar a instalação, configuração, conexão, gerenciamento, backup, restauração e otimização de desempenho do MariaDB, garantindo uma operação eficiente e segura do banco de dados.