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

相关文章

mac安装nvm(node.js)多版本管理实践步骤

《mac安装nvm(node.js)多版本管理实践步骤》:本文主要介绍mac安装nvm(node.js)多版本管理的相关资料,NVM是一个用于管理多个Node.js版本的命令行工具,它允许开发者在... 目录NVM功能简介MAC安装实践一、下载nvm二、安装nvm三、安装node.js总结NVM功能简介N

python安装whl包并解决依赖关系的实现

《python安装whl包并解决依赖关系的实现》本文主要介绍了python安装whl包并解决依赖关系的实现,文中通过图文示例介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录一、什么是whl文件?二、我们为什么需要使用whl文件来安装python库?三、我们应该去哪儿下

MySQL安装时initializing database失败的问题解决

《MySQL安装时initializingdatabase失败的问题解决》本文主要介绍了MySQL安装时initializingdatabase失败的问题解决,文中通过图文介绍的非常详细,对大家的学... 目录问题页面:解决方法:问题页面:解决方法:1.勾选红框中的选项:2.将下图红框中全部改为英

MySQL9.0默认路径安装下重置root密码

《MySQL9.0默认路径安装下重置root密码》本文主要介绍了MySQL9.0默认路径安装下重置root密码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们... 目录问题描述环境描述解决方法正常模式下修改密码报错原因问题描述mysqlChina编程采用默认安装路径,

Python使用国内镜像加速pip安装的方法讲解

《Python使用国内镜像加速pip安装的方法讲解》在Python开发中,pip是一个非常重要的工具,用于安装和管理Python的第三方库,然而,在国内使用pip安装依赖时,往往会因为网络问题而导致速... 目录一、pip 工具简介1. 什么是 pip?2. 什么是 -i 参数?二、国内镜像源的选择三、如何

Python安装时常见报错以及解决方案

《Python安装时常见报错以及解决方案》:本文主要介绍在安装Python、配置环境变量、使用pip以及运行Python脚本时常见的错误及其解决方案,文中介绍的非常详细,需要的朋友可以参考下... 目录一、安装 python 时常见报错及解决方案(一)安装包下载失败(二)权限不足二、配置环境变量时常见报错及

MySQL8.2.0安装教程分享

《MySQL8.2.0安装教程分享》这篇文章详细介绍了如何在Windows系统上安装MySQL数据库软件,包括下载、安装、配置和设置环境变量的步骤... 目录mysql的安装图文1.python访问网址2javascript.点击3.进入Downloads向下滑动4.选择Community Server5.

CentOS系统Maven安装教程分享

《CentOS系统Maven安装教程分享》本文介绍了如何在CentOS系统中安装Maven,并提供了一个简单的实际应用案例,安装Maven需要先安装Java和设置环境变量,Maven可以自动管理项目的... 目录准备工作下载并安装Maven常见问题及解决方法实际应用案例总结Maven是一个流行的项目管理工具

MySql9.1.0安装详细教程(最新推荐)

《MySql9.1.0安装详细教程(最新推荐)》MySQL是一个流行的关系型数据库管理系统,支持多线程和多种数据库连接途径,能够处理上千万条记录的大型数据库,本文介绍MySql9.1.0安装详细教程,... 目录mysql介绍:一、下载 Mysql 安装文件二、Mysql 安装教程三、环境配置1.右击此电脑

在 Windows 上安装 DeepSeek 的完整指南(最新推荐)

《在Windows上安装DeepSeek的完整指南(最新推荐)》在Windows上安装DeepSeek的完整指南,包括下载和安装Ollama、下载DeepSeekRXNUMX模型、运行Deep... 目录在www.chinasem.cn Windows 上安装 DeepSeek 的完整指南步骤 1:下载并安装