删除原有到数据库
[root@localhost ~]#yum -y remove `rpm -qa | grep mariadb`
安装依赖包
[root@localhost ~]# yum -y install autoconf automake cmake gcc-c++ libgcrypt libtool libxml2 ncurses-devel zlib openssl openssl-devel
[root@localhost ~]#yum -y install perl-Data-Dumper python-devel zlib-devel cmake ncurses bison bison-devel
创建用户
[root@localhost ~]#useradd -M -s /sbin/nologin mysql
下载安装包
[root@localhost ~]#yum -y install wget && wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.48.tar.gz
解压到指定目录
[root@localhost ~]# tar -xf mysql-5.6.48.tar.gz
[root@localhost ~]# cd mysql-5.6.48
[root@localhost mysql-5.6.48]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_PARTITION_STORAGE_ENGINE=1
注释:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #安装路径
-DMYSQL_DATADIR=/data/mysql/data \ #数据文件存放位置
-DSYSCONFDIR=/etc \ #my.cnf路径
-DWITH_MYISAM_STORAGE_ENGINE=1 \ #支持MyIASM引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ #支持InnoDB引擎
-DWITH_MEMORY_STORAGE_ENGINE=1 \ #支持Memory引擎
-DWITH_READLINE=1 \ #快捷键功能(我没用过)
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysqld.sock \ #连接数据库socket路径
-DMYSQL_TCP_PORT=3306 \ #端口
-DENABLED_LOCAL_INFILE=1 \ #允许从本地导入数据
-DWITH_PARTITION_STORAGE_ENGINE=1 \ #安装支持数据库分区
-DEXTRA_CHARSETS=all \ #安装所有的字符集
-DDEFAULT_CHARSET=utf8 \ #默认字符
-DDEFAULT_COLLATION=utf8_general_ci
[root@localhost mysql-5.6.48]# make -j `grep processor /proc/cpuinfo | wc -l` && make install
创建文件夹
[root@localhost mysql-5.6.48]# mkdir -p /data/mysql/{log,log-bin,tmp,data}
[root@localhost mysql-5.6.48]#mkdir /var/lib/mysql
[root@localhost mysql]# vim /etc/profile
插入最后
export PATH=/usr/local/mysql/bin:$PATH
[root@localhost mysql]# source /etc/profile
创建所需文件
[root@localhost mysql-5.6.48]#touch /data/mysql/log/mysql.err
改变属主和属组
[root@localhost mysql-5.6.48]#chown -R mysql:mysql /data/mysql
[root@localhost mysql-5.6.48]#chown -R mysql:mysql /var/lib/mysql
[root@localhost mysql-5.6.48]#chown -R mysql:mysql /usr/local/mysql
mysql配置
配置文件
[root@localhost mysql]# vim /etc/my.cnf
[mysqld_safe]
log-error=/data/mysql/log/mysql.err
[mysqld]
datadir=/data/mysql/data
tmpdir=/data/mysql/tmp
socket=/var/lib/mysql/mysql.sock
user=mysql
character_set_server=utf8
default-storage-engine=INNODB
innodb_buffer_pool_size=1G
slow_query_log=1
slow_query_log_file=/data/mysql/log/mysql.slow
long_query_time=2
server_id=1
log-bin=/data/mysql/log-bin/log-bin
binlog_format=row
max_connections=1000
[client]
socket=/var/lib/mysql/mysql.sock
初始化数据库
[root@localhost mysql]#cd /usr/local/mysql
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/data
制作启动脚本
[root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# sed -i '46s|basedir=|basedir=/usr/local/mysql|g' /etc/init.d/mysqld
[root@localhost mysql]# sed -i '47s|datadir=|datadir=/usr/local/mysql/data|g' /etc/init.d/mysqld
将mysqld添加到服务
[root@localhost mysql]# chkconfig --add mysqld
开机自启
[root@localhost mysql]# chkconfig mysqld on
启动
[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
运行安全配置向导
[root@localhost mysql]#ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
[root@localhost mysql]#mysql_secure_installation
Enter current password for root (enter for none):
新安装mysql无root密码,按Enter即可
New password: 设置密码
Re-enter new password:
Password updated successfully!
Reloading privilege tables…
… Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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
… Success!
By default, MySQL 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
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
… Success!
All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up…
搭建完成