centos编译安装mariadb数据库

一、安装编译环境

[root@localhost ]# yum install -y cmake bison bison-devel libaio-devel gcc gcc-c++ git ncurses-devel

二、下载Mariadb

[root@centos ~]# wget http://ftp.hosteurope.de/mirror/archive.mariadb.org/mariadb-10.1.19/source/mariadb-10.1.19.tar.gz
https://wangxuejin-data-1252194948.cos.ap-shanghai.myqcloud.com/mariadb-10.1.19.tar.gz

三、配置

[root@centos ~]# tar xf mariadb-10.1.19.tar.gz
[root@localhost ]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all

配置解释:

1、第一行是安装目录

2、第二行是配置文件目录

3、第三行是默认字符集为utf8

4、第四行是默认字符集的校对规则

5、第五行安装所有字符集

四、编译并安装

[root@localhost ]# make && make install

五、初始化配置

1、用户权限设置

[root@centos local]# chown -R mysql:mysql mysql/

2、MariaDB配置文件创建及更改

[root@centos mysql]# cp support-files/my-medium.cnf /etc/my.cnf

[root@centos mysql]

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

[root@centos mysql]# vim /etc/my.cnf 
datadir = /usr/local/mysql/data/
innodb_file_per_table = on
skip_name_resolve = on

(1)、指定数据库路径

(2)、设置后当创建数据库的表的时候表文件都会分离开,方便复制表,不开启创建的表都在一个文件

(3)、跳过名称反解。Mysql每次使用客户端链接时都会把IP地址反解析成主机名

3、设置环境变量

[root@centos mysql]# vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin

[root@centos mysql]

# source /etc/profile

4、执行脚本初始化数据库

[root@centos mysql]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

5、安全初始化mysql及设定,需要先启动mysql数据库

[root@centos mysql]# /etc/init.d/mysqld start
Starting MySQL.190315 14:58:03 mysqld_safe Logging to '/usr/local/mysql/data//centos.mysql.err'.
. SUCCESS! 

[root@centos mysql]

# mysql_secure_installation  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. Enter current password for root (enter for none): //回车 Set root password? [Y/n] //是否设置root密码 Set 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] //删除匿名账号 Normally, root should only be allowed to connect from 'localhost'.  This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] //是否禁止root账号远程登陆 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. Remove test database and access to it? [Y/n]//是否清除测试数据库 Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] //重载  ... 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!

6、测试能否登录数据库

[root@centos mysql]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 10.1.19-MariaDB Source distribution

Copyright (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)]>

至此Mariadb安装完成

发表评论

后才能评论