Install/use mariadb under Linux

Chapter 1: The use of mariadb on rhel7

Rhel7 and above systems have mariadb (lower version) installed by default
. If the virtual machine is not installed in the system, mount the iso and configure the iso yum -y install mariadb mariadb-serversource
. ! !


The figure below lists the version that comes with rhel7.3. This chapter uses rhel7.3 as an example
mariadb
. Therefore, here is a record of using mariadb that comes with the system.


  1. start mariadb service
systemctl start mariadb
  1. Set the mariadb service to enable self-start (voluntary)
systemctl enable mariadb
  1. Set account password (note: default root has no password)
# 按照提示,一步步执行即可。初始root无密码
mysql_secure_installation
  1. After the password is set successfully, test login
# 用户为root,密码为123456
mysql -uroot -p123456

Chapter 2: Installation of mariadb on rhel6

There is no built-in mariadb on rhel6, if you want to use it, you need to install it yourself.
See below for the operation steps, which may be slightly different.
Reference article: Compile and install MariaDB under CentOS6


The above link provides two ways

(1) Compile the source code package (relatively slow)

  1. Environment preparation before installation
# 1.安装依赖
yum -y install cmake gcc gcc-c++ openssl-devel ncurses-devel
# 2.准备源码包,下载地址:http://archive.mariadb.org/
mariadb-5.5.43.tar.gz
# 3.创建数据存放目录和配置文件目录
mkdir /mydata
mkdir /etc/mysql
  1. precompiled installation
# 1.解压mairadb-5.5.43.tar.gz
tar -zxvf mariadb-5.5.43.tar.gz
# 2.进入解压后的目录
cd mariadb-5.5.43
# 3.执行cmake命令预编译
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb-5.5.43 -DMYSQL_DATADIR=/mydata  -DSYSCONFDIR=/etc/mysql/ -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
# -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb-5.5.43:编译后存放路径
# -DMYSQL_DATADIR=/mydata:数据存放目录
# -DSYSCONFDIR=/etc/mysql:配置文件存放目录
  1. Compile and install
make && make install

(2) Binary package installation (recommended)

  1. Environment preparation before installation
# 1.组和用户:mysql
useradd -r mysql
groupadd -r mysql
# 2.数据存放目录
mkdir -p /mydata
# 3.配置文件目录
mkdir -p /etc/mysql
# 4.二进制包:下载路径http://archive.mariadb.org/
mariadb-5.5.43-linux-x86_64.tar.gz

2. Install

# 1.解压mariadb-5.5.43-linux-x86_64.tar.gz到/usr/local目录中
tar  -zxvf  mariadb-5.5.43-linux-x86_64.tar.gz  -C  /usr/local
mv /usr/local/mariadb-5.5.43-linux-x86_64 /usr/local/mariadb-5.5.43	
# 2.将解压后的目录链接为mysql(ps:不要提前创建/usr/local/mysql目录)
ln  -sv  /usr/local/mariadb-5.5.43  /usr/local/mysql
# 3.进入mysql目录,将所有文件属主改为root,属组改为mysql
cd  /usr/local/mysql
chown  -Rv root:mysql  ./*
# 4.执行scripts目录下mysql_install_db文件,并指明数据存放目录和用户
scripts/mysql_install_db  --datadir=/mydata  --user=mysql	# 注意当前路径为:/usr/local/mysql

insert image description here

3. Post-installation configuration

# 1.将support-files目录下mysql.server文件复制为/etc/rc.d/init.d/mysqld文件
cp support-files/mysql.server  /etc/rc.d/init.d/mysqld
# 2.将其添加到chkconfig启动项
chkconfig --add mysqld
# 3.将support-files目录下my-large.conf复为/etc/mysql/my.cnf文件
cp support-files/my-large.cnf /etc/mysql/my.cnf
# 4.编辑/etc/mysql/my.cnf文件,在[mysqld]添加一下三项(我就添加了一个)
datadir=/mydata
# innodb_file_per_table=on
# skip_name_resolve=on

# 5.配置环境变量,并执行查看
cat /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH #文件内容
# 生效
source /etc/profile.d/mysql.sh
echo $PATH
  1. Installation complete verification

(1) Ideal situation

# 1.启动mysqld服务并查看状态
service mysqld status
service mysqld  start
# 2.抓端口
netstat -ntlp | grep mysql # 看到3306基本就是ok了

Successful example graph:

success


(2) Error reporting (mysqld service cannot start)

The three errors I encountered are written below: (not guaranteed to adapt to all situations)

# 报错a:ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql)
# 解决a:删掉/var/lock/subsys/mysql,再重启服务;
#				重启命令:/etc/init.d/mysql start(一般就会报成功了)
# 注意:重启服务命令不要用service  mysqld  start了,用了还会报同样的错

# 报错b:服务通过上述命令启动成功后,查看服务状态(service mysqld status),
#				显示ERROR! MySQL is running but PID file could not be found
# (也不算解决)解决b:我是没有理会,抓一下mysqld,看看端口开了没,开了应该就没啥问题

# 报错c:/etc/init.d/mysqld: line 213: my_print_defaults: command not found
#       Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe
# 解决c:多半是做链接的时候错了!链接/usr/local/mariadb***到/usr/local/mysql的时候不要提前创建mysql文件夹;
#		提前创建了,目录会多一层,会成为/usr/local/mysql/mariadb***,就会对应不上导致报错!!!(我报错的时候,就是这个问题!)
  1. Start the mysql server

mysql #The following figure is a schematic diagram of successful startup

insert image description here
Reference articles for problem solving:
1. ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists
2. Solve MySQL is running but PID file could not be found
3. Solve Linux: -bash: mysql : command not found problem

Guess you like

Origin blog.csdn.net/Sanayeah/article/details/131463115