linux环境安装mariadb,linux环境下安装Mariadb

linux环境安装mariadb,linux环境下安装Mariadb一、下载安装mariadb是属于mysql的一个分支,是其创始人在mysql被卖给oracle之后重新分出来的,maria取自于他女儿的名字。mariadb完全兼容于mysql,在很多新版本的linux系统中,mysql都已经被替换成了mariadb。mariadb的官网:mariadb官网,下载地址:下载地址。最新稳定版本的下载直链为:wgethttps://downloads.mariadb…

大家好,又见面了,我是你们的朋友全栈君。

一、下载安装

mariadb是属于mysql的一个分支,是其创始人在mysql被卖给oracle之后重新分出来的,maria取自于他女儿的名字。mariadb完全兼容于mysql,在很多新版本的linux系统中,mysql都已经被替换成了mariadb。

mariadb的官网:mariadb官网,下载地址:下载地址。最新稳定版本的下载直链为:

wget https://downloads.mariadb.com/MariaDB/mariadb-10.5.0/bintar-linux-systemd-x86_64/mariadb-10.5.0-linux-systemd-x86_64.tar.gz

1

wgethttps://downloads.mariadb.com/MariaDB/mariadb-10.5.0/bintar-linux-systemd-x86_64/mariadb-10.5.0-linux-systemd-x86_64.tar.gz

首先把安装包下载到本地,然后解压到/usr/local目录:

tar -zxvf mariadb-10.5.0-linux-systemd-x86_64.tar.gz -C /usr/local/

ln -s /usr/local/mariadb-10.5.0-linux-systemd-x86_64/ /usr/local/mysql

1

2

tar-zxvfmariadb-10.5.0-linux-systemd-x86_64.tar.gz-C/usr/local/

ln-s/usr/local/mariadb-10.5.0-linux-systemd-x86_64//usr/local/mysql

初始化数据库,设定数据存储目录为/appdata/mysql,启动用户为mysql:

# 创建mysql用户

useradd -s /sbin/nologin -M mysql

# 创建数据库文件夹

mkdir /appdata/mysql -p

# 初始化数据库

/usr/local/mysql/scripts/mysql_install_db \

–basedir=/usr/local/mysql \

–datadir=/appdata/mysql \

–user=mysql

1

2

3

4

5

6

7

8

9

# 创建mysql用户

useradd-s/sbin/nologin-Mmysql

# 创建数据库文件夹

mkdir/appdata/mysql-p

# 初始化数据库

/usr/local/mysql/scripts/mysql_install_db\

–basedir=/usr/local/mysql\

–datadir=/appdata/mysql\

–user=mysql

初始化数据库的过程中如果报错:

> Installing MariaDB/MySQL system tables in ‘/xxx/mariadb’ …

/usr/local/mariadb/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

Installation of system tables failed! Examine the logs in

/udata/mariadb for more information.

…

1

2

3

4

5

6

7

>InstallingMariaDB/MySQLsystemtablesin’/xxx/mariadb’…

/usr/local/mariadb/bin/mysqld:errorwhileloadingsharedlibraries:libaio.so.1:cannotopensharedobjectfile:Nosuchfileordirectory

Installationofsystemtablesfailed!Examinethelogsin

/udata/mariadbformoreinformation.

…

说明系统缺少组件库libaio,需要安装手动安装:

# centos

yum install libaio libaio-devel

# ubuntu

apt install libaio1

1

2

3

4

# centos

yuminstalllibaiolibaio-devel

# ubuntu

aptinstalllibaio1

执行成功后输出:

Installing MariaDB/MySQL system tables in ‘/appdata/mysql’ …

OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

…

1

2

3

4

5

6

7

InstallingMariaDB/MySQLsystemtablesin’/appdata/mysql’…

OK

Tostartmysqldatboottimeyouhavetocopy

support-files/mysql.servertotherightplaceforyoursystem

…

到这里数据库就已经安装完成了,接下来要做的就是配置。

二、配置

修改my.cnf,设置pid/socket/log等文件的路径,把它们统一存到/appdata/mysql/run/下:

[mysqld]

datadir=/appdata/mysql

socket=/appdata/mysql/run/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

# Settings user and group are ignored when systemd is used.

# If you need to run mysqld under a different user or group,

# customize your systemd unit file for mariadb according to the

# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]

log-error=/appdata/mysql/run/mysql.log

pid-file=/appdata/mysql/run/mysql.pid

[mysql]

socket=/appdata/mysql/run/mysql.sock

[mysqladmin]

socket=/appdata/mysql/run/mysql.sock

#

# include all files from the config directory

#

!includedir /etc/my.cnf.d

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

[mysqld]

datadir=/appdata/mysql

socket=/appdata/mysql/run/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

# Settings user and group are ignored when systemd is used.

# If you need to run mysqld under a different user or group,

# customize your systemd unit file for mariadb according to the

# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]

log-error=/appdata/mysql/run/mysql.log

pid-file=/appdata/mysql/run/mysql.pid

[mysql]

socket=/appdata/mysql/run/mysql.sock

[mysqladmin]

socket=/appdata/mysql/run/mysql.sock

#

# include all files from the config directory

#

!includedir/etc/my.cnf.d

注意:

/appdata/mysql/run目录要提前创建

如果修改了socket的路径,还要修改[mysql]和[mysqladmin]段的socket路径,要和[mysqld]中的socket路径一致

设置路径权限:

chown mysql.mysql -R /usr/local/mysql /appdata/mysql

1

chownmysql.mysql-R/usr/local/mysql/appdata/mysql

添加mysql命令到系统路径,修改/etc/profile文件:

MYSQL_HOME=/usr/local/mysql

export PATH=$PATH:$MYSQL_HOME/bin

1

2

MYSQL_HOME=/usr/local/mysql

exportPATH=$PATH:$MYSQL_HOME/bin

修改后source /etc/profile生效。

三、添加系统服务

3.1 service系统服务

对于使用service命令启动的服务,复制mysql主目录下的support/mysql.server文件到/etc/init.d/:

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

chmod +x /etc/init.d/mysqld

1

2

cp/usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld

chmod+x/etc/init.d/mysqld

然后修改文件中的配置:

basedir=/usr/local/mysql # 安装目录

datadir=/appdata/mysql # 数据目录

mysqld_pid_file_path=/appdata/mysql/run/mysql.pid # pid文件目录

1

2

3

basedir=/usr/local/mysql# 安装目录

datadir=/appdata/mysql# 数据目录

mysqld_pid_file_path=/appdata/mysql/run/mysql.pid# pid文件目录

注意:配置要和上面my.cnf中的配置一一对应

启动:service mysqld start。

添加到开机启动:

chkconfig –add mysqld

chkconfig mysqld on

1

2

chkconfig–addmysqld

chkconfigmysqldon

3.2 systemd系统服务

systemd服务的文件在安装路径/support-files/systemd/mariadb.service:

cp support-files/systemd/mariadb.service /etc/systemd/system/mysqld.service

1

cpsupport-files/systemd/mariadb.service/etc/systemd/system/mysqld.service

复制完后执行systemctl start mysqld启动服务,然后设置开机启动:

systemctl enable mysqld

1

systemctlenablemysqld

四、设置root用户密码

系统服务起来后,可以使用mysqladmin初始化root用户的密码:

mysqladmin -u root password ‘123456’

1

mysqladmin-urootpassword’123456′

如果出现:

d932148070bd94ecf978fdc24436a3e5.png

说明没有没有权限登录,需要通过安全模式启动mysql来修改root密码,在my.cnf中添加以下内容:

[mysqld]

skip-grant-tables

skip-networking

1

2

3

[mysqld]

skip-grant-tables

skip-networking

然后重启服务,使用root身份登录(不用密码),再执行命令修改密码:

use mysql;

# 刷新权限

flush privileges;

# 设置密码

set password for ‘root’@’localhost’ = password(‘123456’);

# 刷新权限

flush privileges;

1

2

3

4

5

6

7

usemysql;

# 刷新权限

flushprivileges;

# 设置密码

set password for’root’@’localhost’=password(‘123456’);

# 刷新权限

flushprivileges;

如果执行命令的时候出现报错:

ERROR 1290 (HY000): The MariaDB server is running with the –skip-grant-tables option so it cannot execute this statement

1

ERROR1290(HY000):TheMariaDBserverisrunningwiththe–skip-grant-tablesoptionsoitcannotexecutethisstatement

说明安全模式下的权限还没有更新,要先刷新一下权限才行:

flush privileges;

1

flushprivileges;

修改完成后去掉my.cnf中添加的参数,重启服务,使用上面设置的密码登陆就可以了:

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 11

Server version: 10.4.8-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]>

1

2

3

4

5

6

7

8

9

WelcometotheMariaDBmonitor.Commandsendwith;or\g.

YourMariaDBconnectionidis11

Serverversion:10.4.8-MariaDBMariaDBServer

Copyright(c)2000,2018,Oracle,MariaDBCorporationAbandothers.

Type’help;’or’\h’forhelp.Type’\c’toclearthecurrentinputstatement.

MariaDB[(none)]>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/133664.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Linux 常用命令解析和Bash Shell使用示例脚本演示

    Linux 常用命令解析和Bash Shell使用示例脚本演示

    2022年1月13日
  • 决策树CART算法、基尼系数的计算方法和含义[通俗易懂]

    决策树CART算法、基尼系数的计算方法和含义[通俗易懂]决策树CART算法——基尼系数决策树的CART算法使用基尼系数来选择划分属性。一个数据集的纯度可以用基尼系数来度量Gini(D)=∑k=1∣y∣∑k′≠kpkpk′=1−∑k=1∣y∣pk2\begin{aligned}Gini(D)=\sum_{k=1}^{|y|}\sum_{k'\nek}p_kp_{k'}=1-\sum_{k=1}^{|y|}…

    2022年10月13日
  • cortex-m3权威指南_core M3

    cortex-m3权威指南_core M3Cortex-M3Bit-Banding1.概述CM3的存储器系统支持所谓的“位带”(bit-band)操作。通过它,实现了对单一bit的原子操作。位带操作仅适用于一些特殊的存储器区域中。从汇编角度看:与传统方法的比较:在位带区中,每个比特都映射到别名地址区的一个字——这是个只有LSB才有效的字。支持位带操作的两个内存区的范围是:0x2000_0000-0x2…

    2022年10月13日
  • 手机版java编译器_Java编译器[通俗易懂]

    手机版java编译器_Java编译器[通俗易懂]这是一款专为学习Java的学员们打造的一款非常优质的程序验证软件,让用户能够非常快速的复制自己的程序到APP中,进行检验,能够非常快速的去验证程序的内容,能够非常及时的进行纠错,让你的代码能够及时的得到解决,用户可以随时在这里打开使用,保证自己的编辑的代码能够更加的完美,让你可以更好的精心纠错,对于初学者来说是一款非常棒的软件,让自己能够学的更好,经验能够更加的丰富。软件特点验证代码非常简单快捷,…

    2022年7月13日
  • python读取excel单元格内容_python如何读取文件夹下的所有文件

    python读取excel单元格内容_python如何读取文件夹下的所有文件1.使用python内建的open()方法读取文本相对路径:example/ex2.txt,文件内容如下所示:测试内容,路径和内容,大家可根据自己心情设置。使用open()方法读取:print(‘—-使用python自带的open()读取文件—–‘)path=r’example/ex2.txt’frame=open(path)print(frame.readlines())此时,执行结果报错如下:我猜测open()方法的…

    2022年10月2日
  • (十一)DSP28335基础教程——EQEP实验(直流电机转速检测)

    (十一)DSP28335基础教程——EQEP实验(直流电机转速检测)0前言这一节我们来学习DSP的EQEP模块的功能。实验目标:通过光电编码器,将采集直流减速电机的转速并显示在LCD1602上。由于28335控制LCD1602的例程并不多,在下面解释的过程会详细贴出代码,并给出一些注意事项。本节将分为硬件部分、软件部分和实验展示三个方面进行介绍,不清楚的欢迎留言。1硬件部分我们需要五个硬件:可调电源、DSP28335核心板、烧写器、自带光电编码器的直流减速电机和LCD1602。其中,电机的额定电压为12V,因此,我们通过可调电源来调整电压,则可以调整电机的转速

    2022年10月7日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号