二进制安装MySQL

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了二进制安装MySQL相关的知识,希望对你有一定的参考价值。

二进制格式的安装方式如下:


1.查询本地是否安装mysql数据库相关的软件包(卸载之)

rpm -qa "mysql*"   (centos6)

rpm -qa "mariaDB*" (cetos7)

2.mariadb.org下载源码二进制包带有linux字样的已经编译过的包:

mariadb-10.2.12-linux-x86_64.tar.gz(大小440M左右因为已经编译过)

3. 准备用户

getent passwd mysql  查询passwd是否有mysql用户

useradd -r mysql -s /sbin/nologin  创建mysql系统用户

[[email protected] ~ 13]#id mysql

uid=990(mysql) gid=305(mysql) groups=305(mysql)

生产环境建议置后一个版本至少.

4.解压mariadb-10.2.12-linux-x86_64.tar.gz

4-1. tar xvf  mariadb-10.2.12-linux-x86_64.tar.gz -C /usr/local/

注意:解压目录指定,因为这是已经编译过的源码包所以路径很重要需要解压到/usr/local/下

4-2.需要改名因为编译之前的目录叫mysql;

建议创建软连接:

ln -s mariadb-10.2.12-linux-x86_64/ mysql

5.修改文件权限默认没有属主属组:(可以不做修改)

chown -R mysql.mysql mysql/

6.导出环境变量:

echo ‘PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh

cat /etc/profile.d/mysql.sh

. /etc/profile.d/mysql.sh (重读配置文件)

7.准备数据目录;建议使用逻辑卷

7-1.创建逻辑卷:

fdiak /dev/sda

7-2.同步磁盘:

partprobe (6 使用pertx)

7-3.创建PV物理卷:

pvcreate /dev/sda6

7-4. 创建卷组:

vgcreate vg0-mysqldata /dev/sda6 -s 16M

7-5.查看卷组:

vgdisplay

7-6.创建LVM

lvcreate -n lv_mysqldata -l 100%FREE vg0mysqldata

7-7.创建逻辑卷的文件系统:

mkfs.xfs /dev/vg0mysqldata/lv_mysqldata

8.创建挂载点并且挂载添加/etc/fstab条目(请注意当前所在的工作目录.我当前的路径是在/usr/local/mysql/bin)

mkdir -pv /data/mysqldb

echo ‘ UUID=98833275-08ee-446f-b888-3e03557deedf /data/mysqldb xfs defaults 0  0‘ >> /etc/fstab (建议别这么添加清空了这个文件就尴尬了)

mount -a 重读/etc/fsatb

9.这连个就是mysql的数据库目录了安全起见建议修改权限为770

chmod 770 /data/mysqldb/

10.初始化数据库:

cd scripts/

scripts/mysql_install_db --datadir=/data/mysqldb --user=mysql

注意:这个脚本一定要在它的上一级目录执行否则会报错

11.由于默认的配置文件过于简陋而且数据库路径也不对,可参考/usr/local/mysql/support-files/目录下以.cnf结尾的模版配置文件.

11-1.cp my-huge.cnf /etc/my.cnf (覆盖目标文件)

修改如下:

12.运行/usr/local/mysql/mysql-server 服务脚本

cp mysql.server /etc/init.d/mysqld 复制并改名mysqld

chkconfig --add mysqld   添加到系统脚本开机启动

13.启动服务:

service mysqld start

源码安装结束

14.查看是否有错误信息

15.查看端口3306

ss -tnl

16.mysql安装完成默认没有密码需要运行一个安全脚本:

. /mysql_secure_installation (交互式设置密码及删除匿名用户)

[[email protected] /usr/local/mysql/bin 178]# ./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旧口令(没有直接回车)

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] 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!

数据化的安全脚本执行完毕后就可以启动服务并测试命令行连接MySQL.

以上是关于二进制安装MySQL的主要内容,如果未能解决你的问题,请参考以下文章

Redhat Linux上mysql安装-binary package安装

Linux平台下安装MySQL

Mysql的二进制安装和基础入门操作

源码安装部署MySQL数据库 二进制安装部署MySQL数据库 yum安装数据库

怎样区分linux下的二进制和源代码Mysql包?

mysql基础进阶