一、Mariadb安装
1. 安装编译环境
[root@Web html]# yum install -y cmake bison bison-devel libaio-devel gcc gcc-c++ git ncurses-devel
2. 已下载Mariadb(10.1.19.tar.gz)
3. 解压压缩包并进入
[root@Web ~]# tar xf mariadb-10.1.19.tar.gz
4. 配置
a) Cmake配置(\后面不能有空格,或在一行执行,此处为方便解释)
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、第五行安装所有字符集
b)
编译并安装
[root@localhost ]# make && make install
5. 初始化数据库
a) 创建mysql数据库用户;
[root@Web mariadb-10.1.19]# useradd -s /sbin/nologin mysql
[root@Web local]# chown -R mysql:mysql /usr/local/mysql/
b) MariaDB配置文件创建及更改
[root@Web local]# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf [root@Web local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
c) 编辑my.cnf
[root@Web local]# vim /etc/my.cnf
在[mysqld]的后面增加配置文件 datadir = /usr/local/mysql/data/ innodb_file_per_table = on skip_name_resolve = on
i. 指定数据库路径
ii. 设置后当创建数据库的表的时候表文件都会分离开,方便复制表,不开启创建的表都在一个文件
iii. 跳过名称反解。Mysql每次使用客户端链接时都会把IP地址反解析成主机名
d) 设置环境变量
[root@Web local]# vim /etc/profile export PATH=$PATH:/usr/local/mysql/bin [root@Web local]# source /etc/profile
e) 执行脚本初始化数据库
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
f) 安全初始化mysql及设定,需要先启动mysql数据库
[root@Web local]# /etc/init.d/mysqld start 启动
Reloading systemd: [ OK ]
Starting mysqld (via systemctl): [ OK ]
[root@Web local]# mysql_secure_installation 初始化设定
Mysql的root密码:***
[root@Web local]# 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):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
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] y
... Success!
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] y
... Success!
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] 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!
g) 测试能否登录数据库
[root@AnshangWeb local]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
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)]>
将mysqld加入到chkconfig
[root@Web bin]# chkconfig --add mysqld
[root@Web bin]# systemctl restart mysqld
至此Mariadb安装完成。
文章评论