二进制程序文件安装方法像windows的绿色版软件一样只需要解压、配置、启动就好
下载地址:
https://downloads.mariadb.org/
https://downloads.mariadb.org/mariadb/10.2.12/
http://mirrors.neusoft.edu.cn/mariadb//mariadb-10.2.12/bintar-linux-x86_64/mariadb-10.2.12-linux-x86_64.tar.gz
1.创建mysql用户
[root@localhost ~]# useradd -r mysql -s /sbin/nologin
[root@localhost ~]# getent passwd mysql
mysql:x:996:994::/home/mysql:/sbin/nologin
2.把mariadb-10.2.12-linux-x86_64.tar.gz文件上传到服务器
解压到官方指定的目录
[root@localhost ~]# tar xf mariadb-10.2.12-linux-x86_64.tar.gz -C /usr/local/
3. 目录结构需要,需创建软链接
cd /usr/local/
[root@localhost local]# ln -s mariadb-10.2.12-linux-x86_64/ mysql
4. 修改相关目录的权限
[root@localhost local]# ll mysql/ -l
total 176
drwxrwxr-x 2 1021 1004 4096 Nov 14 22:34 bin
-rw-r--r-- 1 1021 1004 17987 Jan 3 21:48 COPYING
[root@localhost local]# chown -R mysql.mysql mysql/
[root@localhost local]# ll mysql/ -l
total 176
drwxrwxr-x 2 mysql mysql 4096 Nov 14 22:34 bin
-rw-r--r-- 1 mysql mysql 17987 Jan 3 21:48 COPYING
5.添加PATH变量和立即生效
[root@localhost local]# cd mysql/bin/
[root@localhost bin]# pwd
/usr/local/mysql/bin
[root@localhost bin]# echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost bin]# . /etc/profile.d/mysql.sh
6.创建存放数据库的位置的分区,推荐使用lvm,可随意扩展
创建分区
fdisk /dev/sda
p==>N==>p==>enter==>+5G==>T==>8E==>W
partprobe
安装lvm2包
yum install lvm2
创建lvm步骤,和挂载
pvcreate /dev/sda4 #磁盘初始化pv
pvs
vgcreate vg0 /dev/sda4 -s 16M #创建vg0 加入sda4
vgs
vgdisplay
lvcreate -n lv_mysqldata -l 100%FREE vg0 #创建lv 从vg0取所有容量
lvs
lvdisplay
mkfs.xfs /dev/vg0/lv_mysqldata #创建文件系统
bklid
mkdir /data/mysqldb -pv #创建目录
vi /etc/fstab #写挂载
UUID=86fc6d3c-c681-46e6-8bd5-1fd5f13d0963 /data/mysqldb xfs defaults 0 0
mount -a
设置数据库存放目录的权限
chown -R mysql.mysql /data/mysqldb/
chmod 770 /data/mysqldb/
ll -d /data/mysqldb/
drwxrwx--- 2 mysql mysql 6 Jan 23 18:52 /data/mysqldb/
7.安装创建数据库db
cd /usr/local/mysql/scripts
./mysql_install_db --help 可查看帮助
./scripts/mysql_install_db --datadir=/data/mysqldb --user=mysql 在上级目录执行
初始情况建议配置root密码或者跑安全脚本
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:
'./bin/mysqladmin' -u root password 'new-password'
'./bin/mysqladmin' -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
'./bin/mysql_secure_installation'
8.复制官方配置文件到指定目录和修改
官方配备了不同需求的配置可根据自行需求使用
/usr/local/mysql/support-files
-rw-r--r-- 1 mysql mysql 4914 Jan 3 22:44 my-huge.cnf 1-2G内存使用的
-rw-r--r-- 1 mysql mysql 20421 Jan 3 22:44 my-innodb-heavy-4G.cnf 4G或4G以上
-rw-r--r-- 1 mysql mysql 4901 Jan 3 22:44 my-large.cnf 512M内存使用的
-rw-r--r-- 1 mysql mysql 4914 Jan 3 22:44 my-medium.cnf 32M-64内存使用的
-rw-r--r-- 1 mysql mysql 2840 Jan 3 22:44 my-small.cnf 小于64M内存使用的
拿最低的配置文件测试修改
[root@localhost support-files]# cp my-huge.cnf /etc/my.cnf
vim /etc/my.cnf
# The MySQL server
[mysqld]
port = 3306
datadir =/data/mysqldb ##添加自己数据库存放的路径
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 1M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
9.创建服务和启动服务
cd /usr/local/mysql/support-files
-rwxr-xr-x 1 mysql mysql 1061 Jan 3 22:44 mysqld_multi.server 多实例启动脚本
-rwxr-xr-x 1 mysql mysql 12227 Jan 3 22:44 mysql.server 普通启动脚本
复制启动脚本添加启动
cp mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list
service mysqld start
10.为mysql设置root密码
使用安全脚本
mysql_secure_installation
[root@localhost ~]# 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): #是否配置root密码回车
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y #设置root密码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] n #是否关闭root登陆
... 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.
Remove test database and access to it? [Y/n] y #是否删除数据库里的test数据库
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
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!
11.至此完成,测试
[root@localhost ~]# mysql -uroot -pdaoke
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.2.12-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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)