端口3306
基于源码包安装MySQL
rpm -q mysql mysql-server mariadb mariadb-server(查看这四个服务,如果有要删除rpm格式安装包,安装源码包)
ncurses-devel是cmake的依赖包 ,安装配置工具cmake
安装yum -y install ncurses-devel.x86_64 cmake.x86_64
创建运行用户
useradd -M -s /sbin/nologin mysql
上传Mysql源码包(rz命令上传)
mysql-5.7.24.tar.gz
【a.在/usr/local下创建一个名为boost的文件夹
mkdir /usr/local/boost
b.进入目录并上传(下载)boost
cd /usr/local/boost
boost_1_59_0.tar.gz
tar -xf boost_1_59_0.tar.gz (解压当前位置)
解包,配置,编译,安装
tar -xf mysql-5.7.24.tar.gz -C /usr/src/
cd /usr/src/mysql-5.7.24/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc -DWITH_BOOST=/usr/local/boost&& make && make install (粉色部分为BOSST文件位置)
安装配置项详解
DC-MAKE_INSTALL_PREFIX=/usr/local/mysql //数据库程序安装目录
-DDEFAULT_CHARSET=utf8 //指定字符集编码
-DDEFAULT_COLLATION=utf8_general_ci //默认的字符集校对规则,utf8_general_ci适用于utf-8字符集的通用规则
-DWITH_EXTRA_CHARSETS=all //指定额外支持的字符集编码
-DSYSCONFDIR=/etc //指定配置文件存放目录
安装后的调整
对数据库目录进行权限设置
chown -R mysql:mysql /usr/local/mysql/
vim /etc/my.cnf
建立配置文件(CentOS7系统默认支持MariaDB数据库,系统默认的/etc/my.cnf配置文件是MariaDB的配置文件 )
[mysqld]
datadir=/usr/local/mysql/data (修改路径)
socket=/tmp/mysql.sock (修改路径)
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/usr/local/mysql/data/mysql.log (修改路径)
pid-file=/usr/local/mysql/data/mysql.pid (修改路径)
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
初始化数据库
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
--basedir=/usr/local/mysql/ //指定安装目录(产品目录)
--datadir=/usr/local/mysql/data //指定数据目录
--user=mysql //指定用户身份
设置环境变量
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
添加系统服务
添加MySQL为系统服务,以便通过systemctl命令进行管理
cp /usr/src/mysql-5.7.24/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld 为服务启动脚本
mysql端口号为3306
mysql -uroot -p'+ein2Z>F+AnI' 登陆mysql
mysqladmin -uroot -p'+ein2Z>F+AnI' password '123456' 修改密码