千家信息网

CentOS-6上安装二进制Mariadb

发表于:2024-12-13 作者:千家信息网编辑
千家信息网最后更新 2024年12月13日,前言:mariadb官方网站上提供了三种不同形式的程序包:源码包版、程序包管理器版、和二进制版,如下图所示。二进制版是由官方编译好的绿色版,相比源码包版安装更简单,比起程序包管理器版又多一点自由度,算
千家信息网最后更新 2024年12月13日CentOS-6上安装二进制Mariadb

前言:

mariadb官方网站上提供了三种不同形式的程序包:源码包版、程序包管理器版、和二进制版,如下图所示。二进制版是由官方编译好的绿色版,相比源码包版安装更简单,比起程序包管理器版又多一点自由度,算是二者的折中方案。另外要注意它依赖于glibc,需要注意glibc的版本。

安装:

步骤一:

首先确认glibc版本,可以看到CentOS-6上安装的是glibc-2.12版,所以需要下载

# rpm -q glibcglibc-2.12-1.166.el6.x86_64

步骤二:

关闭iptables和SElinux


步骤三:

# 创建系统用户mysql

# useradd -r mysql

# 解压至目录/usr/local/

# tar -xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local/

# 创建软链接mysql

# cd /usr/local/# ln -sv mariadb-5.5.43-linux-x86_64/ mysql"mysql" -> "mariadb-5.5.43-linux-x86_64/"

# 修改目录属主和属组

# chown -R root:mysql .

# 创建数据库目录。如果不单独创建并指定则默认使用当前目录下的data目录作为数据库目录

# mkdir -pv /data/mysqlmkdir: created directory `/data'mkdir: created directory `/data/mysql'

# 修改数据库目录的属主和属组为mysql

# chown -R mysql:mysql /data/mysql/

# 安装数据库

# scripts/mysql_install_db --user=mysql --datadir=/data/mysql


配置

# 将bin目录路径导入PATH环境变量

# vim /etc/profile.d/mysql.shexport PATH=/usr/local/mysql/bin:$PATH

# 立即生效

# exec bash

# 创建头文件符号链接

# cd /usr/local/include/# ln -s ../mysql/include/mysql/ mysql

# 将man路径导入系统man手册

# vim /etc/man.configMANPATH /usr/local/mysql/man

# 拷贝服务脚本至/etc/rc.d/init.d目录

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

# 复制模板配置文件至/etc/目录

# cp support-files/my-large.cnf /etc/my.cnf

# 修改配置文件

# vim /etc/my.cnf

字符集:

mysqld为服务端,mysql为本地cli命令行工具,client为客户端连接工具包括远程连接工具等。均需要将字符集统一设置为utf-8,特殊场景根据实际情况修改为其他字符集。

[client]default-charater-set=utf8[mysql]default-charater-set=utf8[mysqld]character-set-server=utf8


字符排序:

[mysqld]collation-server=utf8_general_ci


数据库目录

[mysqld]datadir=/data/mysql


存储引擎

[mysqld]# 默认使用innodb存储引擎default-storage-engine=InnoDB# 每张表都使用独立表空间innodb-file-per-table=TRUE


关闭域名反解

skip-name-resolve=TRUE


配置完成后应该是这个样子

[client]port            = 3306socket          = /tmp/mysql.sockdefault-character-set=utf8[mysqld]datadir=/data/mysqlport            = 3306socket          = /tmp/mysql.sockskip-external-lockingkey_buffer_size = 256Mmax_allowed_packet = 1Mtable_open_cache = 256sort_buffer_size = 1Mread_buffer_size = 1Mread_rnd_buffer_size = 4Mmyisam_sort_buffer_size = 64Mthread_cache_size = 8query_cache_size= 16Mthread_concurrency = 8character-set-server=utf8collation-server=utf8_general_cidefault-storage-engine=InnoDBinnodb-file-per-table=TRUEskip-name-resolve=TRUElog-bin=mysql-binskip-name-resolve=TRUElog-bin=mysql-binbinlog_format=mixedserver-id       = 1[mysqldump]quickmax_allowed_packet = 16M[mysql]no-auto-rehashdefault-character-set=utf8[myisamchk]key_buffer_size = 128Msort_buffer_size = 128Mread_buffer = 2Mwrite_buffer = 2M[mysqlhotcopy]interactive-timeout


启动服务

/etc/init.d/mysqld start

开机自启动

chkconfig --add mysqldchkconfig mysqld on

安全设置

# mysql_secure_installation /usr/local/mysql/bin/mysql_secure_installation: line 379: find_mysql_client: command not foundNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!In order to log into MariaDB to secure it, we'll need the currentpassword for the root user.  If you've just installed MariaDB, andyou haven't set the root password yet, the password will be blank,so you should just press enter here.# 初始root密码为空,直接回车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 MariaDBroot user without the proper authorisation.#设置root密码Set root password? [Y/n] n ... skipping.By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem.  This is intended only for testing, and to make the installationgo a bit smoother.  You should remove them before moving into aproduction environment.# 删除匿名用户Remove anonymous users? [Y/n] n ... skipping.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] n ... skipping.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.# 删除test数据库以及访问它的权限设置Remove test database and access to it? [Y/n] n ... skipping.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!


0