官网二进制mariadb很多配置使写死的。所以配置文件的位置请留意不要出错哦。如/usr/loacl/mysql等。
1.确认没有maraiadb*包
rpm -qa mariadb*查看无包即可,若有,用yum remove 包名卸载即可。
mariadb软件包官网下载即可。
2.创建系统用户。很多服务都会用到对应的服务帐户。由于我们是手动安装,这个帐户只好自己创建了。
useradd -d /app/mysqldb -r -m -s /sbin/nologin mysql
getent passwd mysql
建议放在逻辑卷上,数据库会不断变大,不能扩展的分区后期处理起来就麻烦多了。
3.解压
tar xf mariadb-VERSION-linux-x86_64.tar.gz -C /usr/local
cd /usr/local
ln -sv mariadb-10.2.8-linux-x86_64 mysql v显示过程
4.准备配置文件
mkdir /etc/mysql
cp /usr/local/mysqlsupport-files/my-huge.cnf /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
下面意为[mysqld]行下加入如下三行。
[mysqld]
datadir = /app/mysqldb 必须加
innodb_file_per_table = on 每表为一独立文件
skip_name_resolve = on 性能优化,禁止主机名解析
5../scripts/mysql_install_db --user=mysql --datadir=/app/mysqldb 运行脚本,创建系统数据库
ls /app/mysqldb 有东西了
(可能有报错,根据报错提醒,逐一排错)
因为是二进制编译,有些配置文件的位置是设定好的,这点需注意。
1
2
3
4
5
|
[root@centos7 mysql] # ./scripts/mysql_install_db --datadir=/app/mysqldb --user=mysql
Installing MariaDB /MySQL system tables in '/app/mysqldb' ...
2017-10-11 20:08:53 140592457275200 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
2017-10-11 20:08:55 140592457275200 [ERROR] . /bin/mysqld : unknown variable 'datedir=/app/mysqldb'
2017-10-11 20:08:55 140592457275200 [ERROR] Aborting |
6.准备服务脚本,并启动服务
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --list mysqld
chkconfig --add mysqld
service mysqld start
下面是服务不能启动的情况
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
[root@centos7 mysql] # service mysqld start
Starting mysqld (via systemctl): Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
[FAILED]
[root@centos7 mysql] # systemctl status mysqld.service -l
● mysqld.service - LSB: start and stop MySQL Loaded: loaded ( /etc/rc .d /init .d /mysqld ; bad; vendor preset: disabled)
Active: failed (Result: exit -code) since Wed 2017-10-11 20:20:27 CST; 3min 32s ago
Docs: man :systemd-sysv-generator(8)
Process: 10519 ExecStart= /etc/rc .d /init .d /mysqld start (code=exited, status=1 /FAILURE )
Oct 11 20:20:26 centos7.magedu.com systemd[1]: Starting LSB: start and stop MySQL... Oct 11 20:20:26 centos7.magedu.com mysqld[10519]: Starting MySQL.171011 20:20:26 mysqld_safe Logging to '/var/log/mariadb/mariadb.log' .
Oct 11 20:20:26 centos7.magedu.com mysqld[10519]: 171011 20:20:26 mysqld_safe Starting mysqld daemon with databases from /app/mysqldb
Oct 11 20:20:26 centos7.magedu.com mysqld[10519]: [133B blob data] Oct 11 20:20:27 centos7.magedu.com mysqld[10519]: ERROR! Oct 11 20:20:27 centos7.magedu.com systemd[1]: mysqld.service: control process exited, code=exited status=1 Oct 11 20:20:27 centos7.magedu.com systemd[1]: Failed to start LSB: start and stop MySQL. Oct 11 20:20:27 centos7.magedu.com systemd[1]: Unit mysqld.service entered failed state. Oct 11 20:20:27 centos7.magedu.com systemd[1]: mysqld.service failed. |
可以看到缺少了日志文件,日志文件对于mysql数据库还是很重要的。有时出现任务进行一半意外中断的情况,日志可以快速排错。接下来我们创建日志文件。注意权限。权限不对会导致服务无法启动。
touch /var/log/mariadb/mariadb.log
chown mysql /var/log/mariadb/mariadb.log
chown mysql /var/log/mariadb
service mysqld start
7.安全初始化环境配置
主要包括PATH环境变量及安全环境。
[root@centos7 mysql]# vim /etc/profile.d/mysql.sh
PATH=/usr/local/mysql/bin/:$PATH
可以同时开一个终端测试.
A:
1
2
3
4
5
6
7
8
9
|
[root@centos7 bin] # cd /usr/local/mysql/bin
[root@centos7 bin] # ./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):
|
B:查看当前登录用户
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@centos7 ~] # mysql
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10
Server version: 10.2.8-MariaDB-log MariaDB Server Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> select user();
+----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec)
|
A:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
[root@centos7 bin] # ./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 ]
|
B:
1
2
|
[root@centos7 ~] # mysql
ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: NO)
|
设置完成后再以root身份登录就要执行mysql -uroot -p命令了。
本文转自阿拉杜美美51CTO博客,原文链接: http://blog.51cto.com/amelie/1971534,如需转载请自行联系原作者