centos7.2 源码安装mariadb10.1

来源:互联网 发布:手机淘宝如何找旗舰店 编辑:程序博客网 时间:2024/06/14 12:58

昨天又用源码重新安装了一次mariadb一样还是做个总结吧.
服务器环境还是刚安装了Apache2.4的centos7.2,话不多说开工

安装所需准备

安装mariadb 需要cmake 和依赖包readline-devel,zlib-devel,openssl-devel,libaio-devel readline-devel 还是先用yum工具安装一下吧

yum -y install readline-develyum -y install zlib-develyum -y install openssl-develyum -y install libaio-develyum -y install cmake

创建mysql用户和安装目录,数据存放目录

groupadd -r mysql#创建mysql用户组useradd -g mysql -s /sbin/nologin mysql#创建mysql用户归属于mysql组mkdir /usr/local/mysql#创建mariadb安装目录mkdir -p /data/db #创建数据存储目录chown -R mysql:mysql /data/db/ #给予权限

下载mariadb源码包

下载地址:https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.1.21/source/mariadb-10.1.21.tar.gz 其他版本
使用wget下载:

wget https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.1.21/source/mariadb-10.1.21.tar.gz 

或者使用桌面环境下载了用ssh上传到linux(我使用的腾讯云服务器,只有1mbps的小水管,下载非常慢,但是我发现使用ssh上传可以达到6mbps的网速,比直接在服务器上下载快多了)

开始安装

解压源码包

tar -xf mariadb-10.1.21/source/mariadb-10.1.21.tar.gz

进入源码包目录

cd mariadb-10.1.21

编译源码包

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/db -DSYSCONFDIR=/etc -DWITHOUT_TOKUDB=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
  • -DCMAKE_INSTALL_PREFIX是指定安装的位置,这里是/usr/local/mysql
  • -DMYSQL_DATADIR是指定MySQL的数据目录,这里是/data/db
  • -DSYSCONFDIR是指定配置文件所在的目录,一般都是/etc,具体的配置文件是/etc/my.cnf,-DWITHOUT_TOKUDB=1这个参数一般都要设置上,表示不安装tokudb引擎,tokudb是MySQL中一款开源的存储引擎,可以管理大量数据并且有一些新的特性,这些是Innodb所不具备的,这里之所以不安装,是因为一般计算机默认是没有Percona Server的,并且加载tokudb还要依赖jemalloc内存优化,一般开发中也是不用tokudb的,所以暂时屏蔽掉,否则在系统中找不到依赖会出现:CMake Error at storage/tokudb/PerconaFT/cmake_modules/TokuSetupCompiler.cmake:179 (message)这样的错误
  • -DDEFAULT_CHARSET 字符集,这里是utf-8
  • -DDEFAULT_COLLATION排序规则,这里是utf8_general_ci
    如果编译遇到错误使用rm -f CMakeCache.txt删除编译缓存后尝试重新编译

安装

make && make install

完成安装

cd /usr/local/mysql/#进入mariadb安装目录chown -R mysql:mysql . #给予mysql:mysql权限scripts/mysql_install_db --datadir=/data/db --user=mysql #初始化系统表cp support-files/mysql.server /etc/init.d/mysqldchkconfig --add mysqld   # 添加至系统服务chkconfig mysqld on    # 设置开机自启动echo export PATH=/usr/local/mysql/bin:$PATH >>/etc/profile.d/mysql.sh #导出环境变量source /etc/profile # 应用环境变量

安装完成后在安装目录下的support-file目录下有my-small.cnf、my-medium.cnf、my-large.cnf以及my-huge.cnf,这是示例的配置文件,可以把他们替换到etc下的my.cnf再做适当修改

cp -f /usr/local/mysql/support-file/my-small.cnf /etc/my.cnf

再在配置文件中做如下修改

basedir=/usr/local/mysql #mariadb安装目录datadir=/data/db#数据存放目录pid-file=data/db/mariadb.pidlog-error=/log/mariadb.err #mariadb告警日志 启动失败可以查看该日志

可以启动mariadb服务了

service mysqld start#启动start 停止stop 重启restart

执行安全初始化脚本

mysql_secure_installation/usr/local/mysql/bin/mysql_secure_installation: line 379: find_mysql_client: command not foundNOTE: 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 currentpassword for the root user.  If you've just installed MariaDB, andyou 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 MariaDBroot user without the proper authorisation.You already have a root password set, so you can safely answer 'n'.#改变root用户的密码;Change the root password? [Y/n] YNew password:Re-enter new password:Password updated successfully!Reloading privilege tables.. ... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem.  This is intended only for testing, and to make the installationgo a bit smoother.  You should remove them before moving into aproduction environment.#移除匿名用户;Remove anonymous users? [Y/n] Y ... Success!Normally, root should only be allowed to connect from 'localhost'.  Thisensures that someone cannot guess at the root password from the network.#禁止root用户远程登录;Disallow root login remotely? [Y/n] Y ... Success!By default, MariaDB comes with a database named 'test' that anyone canaccess.  This is also intended only for testing, and should be removedbefore moving into a production environment.#不移除test数据库;Remove test database and access to it? [Y/n] n ... skipping.Reloading the privilege tables will ensure that all changes made so farwill 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 MariaDBinstallation should now be secure.Thanks for using MariaDB!

当前状态下我们不能远程登录到数据库,因为受到user表的限制,在非生产环境下我们可以把user表里面的host字段改为”%” 这样就可以在任意地址远程登录到数据库ps:注意这样非常不安全不能在生产环境下这样设置

mysql -uroot -p#登录mysqlEnter password:  #输入密码MariaDB [(none)]> update mysql.user set host="%" where host="127.0.0.1";
0 0
原创粉丝点击