ubuntu16.04下安装mariadb

2024-06-20 19:48
文章标签 安装 mariadb ubuntu16.04

本文主要是介绍ubuntu16.04下安装mariadb,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1 安装

# apt-get install mariadb-server python-pymysql
安装的时候会要求输入 root密码。

有时需要更新本地的仓库:

sudo apt-get update

2 从命令行中进入MariaDB:

mysql -uroot -p

3 从命令行连接到MariaDB

root@zhai:~# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 42
Server version: 10.0.25-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> Ctrl-C -- exit!
Aborted

4 查看数据库是否安装成功

root@zhai:~# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 32
Server version: 10.0.25-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8mb4                    |
| character_set_connection | utf8mb4                    |
| character_set_database   | utf8mb4                    |
| character_set_filesystem | binary                     |
| character_set_results    | utf8mb4                    |
| character_set_server     | utf8mb4                    |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)MariaDB [(none)]> show variables like 'collation%';
+----------------------+--------------------+
| Variable_name        | Value              |
+----------------------+--------------------+
| collation_connection | utf8mb4_general_ci |
| collation_database   | utf8mb4_general_ci |
| collation_server     | utf8mb4_general_ci |
+----------------------+--------------------+
3 rows in set (0.00 sec)
能查看到表说明安装成功。

5 MariaDB 服务启动与停止

$ sudo /etc/init.d/mysql stop
$ sudo /etc/init.d/mysql start

重启:

# service mysql restart

6 MySQL 设置默认字符集

打开/etc/mysql/my.cnf文件,为[mysqld]添加如下设置:

[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8

然后重启 MySQL。

7 加强MariaDB安全设置

MariaDB安装成功后,执行指令mysql_secure_installation加强MariaDB的安全设置:

 
root@zhai:~# mysql_secure_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you 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 MariaDB
root user without the proper authorisation.You already have a root password set, so you can safely answer 'n'.Change the root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..... Success!By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [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.
//是否禁止 root 账户远程登录?
Disallow root login remotely? [Y/n] y ... Success!By default, MariaDB 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.
//是否删除 MariaDB 默认创建的 test 数据库,并删除所有对 test 数据库的权限设置?
Remove test database and access to it? [Y/n] y - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't 
exist ... Failed! Not critical, keep moving... - Removing privileges on test 
database... ... Success!Reloading the privilege tables will ensure that all 
changes made so farwill take effect immediately.
//是否重新加载权限表?
Reload privilege tables now? [Y/n] y ... Success!Cleaning up...All done! If you've 
completed all of the above steps, your MariaDBinstallation should now be secure.
Thanks for using MariaDB!


7 设置MariaDB允许远程访问

7.1 如果Ubuntu有设置防火墙或者iptables规则的话,请自行打开


7.2 3306端口是不是没有打开?

使用nestat命令查看3306端口状态:

~# netstat -an | grep 3306

tcp0  0 127.0.0.1:3306  0.0.0.0:*   LISTEN

从结果可以看出3306端口只是在IP 127.0.0.1上监听,所以拒绝了其他IP的访问。

解决方法:修改/etc/mysql/my.cnf文件。打开文件,找到下面内容:

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address  = 127.0.0.1

把上面这一行注释掉或者把127.0.0.1换成合适的IP,建议注释掉。

重新启动后,重新使用netstat检测:

~# netstat -an | grep 3306
tcp0  0 0.0.0.0:33060.0.0.0:*   LISTEN


7.3 现在使用下面命令测试:

~# mysql -h 192.168.0.101 -u root -p
Enter password:
ERROR 1130 (00000): Host 'Ubuntu-Fvlo.Server' is not allowed to connect to this MySQL server

结果出乎意料,还是不行。

解决方法:原来还需要把用户权限分配各远程用户。

登录到mysql服务器,使用grant命令分配权限

mysql> grant all on *.* to 你的用户名如root@'%' identified by '你的密码';

完成后使用mysql命令连接,提示成功,为了确保正确可以再远程登陆测试一下。


参考:

fedora 22 MariaDB:http://www.linuxdiyf.com/linux/15398.html

在Linux中怎样将MySQL迁移到MariaDB上:http://www.linuxdiyf.com/linux/14127.html

15个有用的MySQL/MariaDB性能调整和优化技巧:http://www.linuxdiyf.com/linux/12780.html

Linux有问必答:如何检查MariaDB服务端版本:http://www.linuxdiyf.com/linux/13554.html

ubuntu15.04安装mariadb10.0.19:http://www.linuxdiyf.com/linux/12325.htm


这篇关于ubuntu16.04下安装mariadb的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1079086

相关文章

Python中win32包的安装及常见用途介绍

《Python中win32包的安装及常见用途介绍》在Windows环境下,PythonWin32模块通常随Python安装包一起安装,:本文主要介绍Python中win32包的安装及常见用途的相关... 目录前言主要组件安装方法常见用途1. 操作Windows注册表2. 操作Windows服务3. 窗口操作

k8s上运行的mysql、mariadb数据库的备份记录(支持x86和arm两种架构)

《k8s上运行的mysql、mariadb数据库的备份记录(支持x86和arm两种架构)》本文记录在K8s上运行的MySQL/MariaDB备份方案,通过工具容器执行mysqldump,结合定时任务实... 目录前言一、获取需要备份的数据库的信息二、备份步骤1.准备工作(X86)1.准备工作(arm)2.手

gitlab安装及邮箱配置和常用使用方式

《gitlab安装及邮箱配置和常用使用方式》:本文主要介绍gitlab安装及邮箱配置和常用使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装GitLab2.配置GitLab邮件服务3.GitLab的账号注册邮箱验证及其分组4.gitlab分支和标签的

MySQL MCP 服务器安装配置最佳实践

《MySQLMCP服务器安装配置最佳实践》本文介绍MySQLMCP服务器的安装配置方法,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下... 目录mysql MCP 服务器安装配置指南简介功能特点安装方法数据库配置使用MCP Inspector进行调试开发指

在Windows上使用qemu安装ubuntu24.04服务器的详细指南

《在Windows上使用qemu安装ubuntu24.04服务器的详细指南》本文介绍了在Windows上使用QEMU安装Ubuntu24.04的全流程:安装QEMU、准备ISO镜像、创建虚拟磁盘、配置... 目录1. 安装QEMU环境2. 准备Ubuntu 24.04镜像3. 启动QEMU安装Ubuntu4

Python UV安装、升级、卸载详细步骤记录

《PythonUV安装、升级、卸载详细步骤记录》:本文主要介绍PythonUV安装、升级、卸载的详细步骤,uv是Astral推出的下一代Python包与项目管理器,主打单一可执行文件、极致性能... 目录安装检查升级设置自动补全卸载UV 命令总结 官方文档详见:https://docs.astral.sh/

Nexus安装和启动的实现教程

《Nexus安装和启动的实现教程》:本文主要介绍Nexus安装和启动的实现教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、Nexus下载二、Nexus安装和启动三、关闭Nexus总结一、Nexus下载官方下载链接:DownloadWindows系统根

Java SWT库详解与安装指南(最新推荐)

《JavaSWT库详解与安装指南(最新推荐)》:本文主要介绍JavaSWT库详解与安装指南,在本章中,我们介绍了如何下载、安装SWTJAR包,并详述了在Eclipse以及命令行环境中配置Java... 目录1. Java SWT类库概述2. SWT与AWT和Swing的区别2.1 历史背景与设计理念2.1.

安装centos8设置基础软件仓库时出错的解决方案

《安装centos8设置基础软件仓库时出错的解决方案》:本文主要介绍安装centos8设置基础软件仓库时出错的解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录安装Centos8设置基础软件仓库时出错版本 8版本 8.2.200android4版本 javas

Pytorch介绍与安装过程

《Pytorch介绍与安装过程》PyTorch因其直观的设计、卓越的灵活性以及强大的动态计算图功能,迅速在学术界和工业界获得了广泛认可,成为当前深度学习研究和开发的主流工具之一,本文给大家介绍Pyto... 目录1、Pytorch介绍1.1、核心理念1.2、核心组件与功能1.3、适用场景与优势总结1.4、优