对于服务器的环境,个人觉得还是源码编译安装的非常靠谱,假如有服务器要变更,直接rm掉安装目录即可。有些人喜欢yum安装,但是在卸载yum remove的时候,一不小心,就卸载了一个基础库,导致系统的shell命令失效,情节严重的可能连系统启动都会存在问题。
1. 安装系统的一些必要基础库
yum -y install gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake bison bison-devel
2. 新增mysql的用户,并且限制mysql登录,只是作为服务用户使用而已
#新增用户组 groupadd mysql #新增用户 useradd mysql -g mysql -s /sbin/nologin
3.建立数据库基础目录
#创建数据库执行文件目录 mkdir -p /data/mysql-5.6/data/ #创建数据库文件目录 mkdir -p /data/mysql-5.6 # 修改目录拥有者 chown -R mysql:mysql /data/mysql-5.6/data/ chown -R mysql:mysql /data/mysql-5.6 chown -R mysql:mysql /data/mysql-5.6/data/. chown -R mysql:mysql /data/mysql-5.6/.
4.编译安装
vi /etc/profile #在该文件的末尾,添加 path变量 PATH=/data/mysql-5.6/bin:/data/mysql-5.6/lib:$PATH export PATH #让配置的path变量生效 source /etc/profile #安装编译源码所需的工具和库 yum -y install wget gcc-c++ ncurses-devel cmake make perl #进入压缩包目录解压并且编译 cd /data/src/mysql-5.6.10 cmake -DCMAKE_INSTALL_PREFIX=/data/mysql-5.6 -DMYSQL_UNIX_ADDR=/data/mysql-5.6/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql-5.6/data -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3339 -DENABLE_DOWNLOADS=1 (出现Googlemock was not found. 加上) -DWITH_DEBUG=0 #编译安装 make && make install #复制启动文件,以便以后直接services的方式启动,开机自启动等。。 cp -ar /data/mysql-5.6/support-files/mysql.server /etc/init.d/mysqld #安装数据库 ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql-5.6/data/ # 复制配置文件 cp -ar /data/mysql-5.6/support-files/my-default.cnf /etc/my.cnf #编辑/etc/my.cnf,修改一下基础路径,要不然会出现启动错误。因为我们在编译的时候填写默认的安装目录和配置文件目录等等。 [mysqld] datadir=/data/mysql-5.6/data/ socket=/data/mysql-5.6/tmp/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/data/log/mysqld.log pid-file=/data/mysql-5.6/tmp/mysqld.pid #启动mysqld服务 /etc/init.d/mysqld start
到这里,我们的mysql源码编译已经安装成功了,下面需要我们对数据库做一些安全性的设置。
删除数据的test数据库。
[root@AY140718141902043917Z tmp]# mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.10 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) mysql> drop database test; Query OK, 0 rows affected (0.00 sec)
2.修改数据库的访问权限。
mysql> select user,password,host from mysql.user; +------+----------+-----------------------+ | user | password | host | +------+----------+-----------------------+ | root | | localhost | | root | | AY140718141902043917Z | | root | | 127.0.0.1 | | root | | ::1 | | | | localhost | | | | AY140718141902043917Z | +------+----------+-----------------------+ 6 rows in set (0.00 sec) #删除空的账户 mysql> delete from mysql.user where user=‘‘; Query OK, 2 rows affected (0.00 sec) #创建授权账户 mysql> grant all privileges on aisk.* ‘tomer‘@‘10.%‘ indentified by ‘HjYk‘ with grant option;
本文出自 “-=湖边竹=-” 博客,请务必保留此出处http://bronte.blog.51cto.com/2418552/1441182
原文地址:http://bronte.blog.51cto.com/2418552/1441182