设置Mariadb的yum源 mysql
vim /etc/yum.repos.d/mariadb.repo [mariadb] name=mariadb baseurl=https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/10.2/centos7-amd64/ gpgcheck=0
使用清华yum源安装Mariadb,能够选择不一样的版本,此处安装10.2.23 yum install mariadb-server
linux
1 准备mysql用户和组 sql
groupadd -r -g 336 mysql #建立mysql组 useradd -r -g mysql -u 336 -s /sbin/nologin -d /data/mysql mysql #建立mysql用户,并加入mysql用户组,设置UID为336,设置默认shell为nologoin,家目录为/data/mysql 但不自动建立
2 准备二进制程序文件和相关文件属性 shell
tar xvf mariadb-10.2.23-linux-x86_64.tar.gz -C /usr/local #只能放在此目录中 cd /usr/local/ ln -s mariadb-10.2.23-linux-x86_64/ mysql #创建软件连接,方便使用 chown -R root.root /usr/local/mysql/ #设置属主和属组为root用户和root组
3 PATH变量 数据库
vim /etc/profile.d/mysql.sh PATH=/usr/local/mysql/bin:$PATH . /etc/profile.d/mysql.sh
4 准备数据库数据目录和数据(使用逻辑卷) vim
建立逻辑卷 pvcreate /dev/sda6 建立卷组 vgcreate vg0 /dev/sda6 建立逻辑卷 lvcreate -n mysql -L 20G /dev/vg0 建立文件系统并挂载到/data/mysql mkfs.xfs /dev/vg0/mysql mkdir /data/mysql mount /dev/vg0/mysql /data/mysql chown mysql.mysql /data/mysql/ cd /usr/local/mysql ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql #安装mysql到/data/mysql目录下,用户为mysql
5 准备Mysql的服务器端配置文件 centos
mkdir /etc/mysql cp /usr/local/mysql/support-files/my-huge.cnf /etc/mysql/my.cnf vim /etc/mysql/my.cnf [mysqld] datadir=/data/mysql #设置目录为/data/mysql
6 准备服务启动脚本 安全
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chkconfig --add mysqld service mysqld start
7 安全加固 服务器
[root@Centos7 ~]#/usr/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 #设置root用户密码 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 #禁止root远程登陆 ... 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] 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!
8 测试链接
mysql -uroot -pPASSWORD ide