CentOS-6上安装二进制Mariadb
前言:
10年积累的成都网站设计、成都网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作后付款的网站建设流程,更有呼兰免费网站建设让你可以放心的选择与我们合作。
mariadb官方网站上提供了三种不同形式的程序包:源码包版、程序包管理器版、和二进制版,如下图所示。二进制版是由官方编译好的绿色版,相比源码包版安装更简单,比起程序包管理器版又多一点自由度,算是二者的折中方案。另外要注意它依赖于glibc,需要注意glibc的版本。
安装:
步骤一:
首先确认glibc版本,可以看到CentOS-6上安装的是glibc-2.12版,所以需要下载
# rpm -q glibc glibc-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/mysql mkdir: 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.sh export PATH=/usr/local/mysql/bin:$PATH
# 立即生效
# exec bash
# 创建头文件符号链接
# cd /usr/local/include/ # ln -s ../mysql/include/mysql/ mysql
# 将man路径导入系统man手册
# vim /etc/man.config MANPATH /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 = 3306 socket = /tmp/mysql.sock default-character-set=utf8 [mysqld] datadir=/data/mysql port = 3306 socket = /tmp/mysql.sock skip-external-locking key_buffer_size = 256M max_allowed_packet = 1M table_open_cache = 256 sort_buffer_size = 1M read_buffer_size = 1M read_rnd_buffer_size = 4M myisam_sort_buffer_size = 64M thread_cache_size = 8 query_cache_size= 16M thread_concurrency = 8 character-set-server=utf8 collation-server=utf8_general_ci default-storage-engine=InnoDB innodb-file-per-table=TRUE skip-name-resolve=TRUE log-bin=mysql-bin skip-name-resolve=TRUE log-bin=mysql-bin binlog_format=mixed server-id = 1 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash default-character-set=utf8 [myisamchk] key_buffer_size = 128M sort_buffer_size = 128M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout
启动服务
/etc/init.d/mysqld start
开机自启动
chkconfig --add mysqld chkconfig mysqld on
安全设置
# mysql_secure_installation /usr/local/mysql/bin/mysql_secure_installation: line 379: find_mysql_client: command not found NOTE: 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 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. # 初始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 MariaDB root user without the proper authorisation. #设置root密码 Set root password? [Y/n] n ... skipping. 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] n ... skipping. Normally, root should only be allowed to connect from 'localhost'. This ensures 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 can access. This is also intended only for testing, and should be removed before 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 far will 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 MariaDB installation should now be secure. Thanks for using MariaDB!
网站名称:CentOS-6上安装二进制Mariadb
文章网址:http://azwzsj.com/article/poijio.html