源码包安装MySQL
MySQL安装方式
1.二进制安装
2.源码包安装
3.rpm包安装
一.源码包安装
源码包安装比较繁琐,但是更加灵活,可以按自己需求配置
1.下载源码包
[root@db03~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.6.46.tar.gz
2.安装需要的依赖包
[root@db03 ~]# yum install -y ncurses-devel libaio-devel gcc gcc-c++ glibc cmake autoconf openssl openssl-devel
3.解压源码包
[root@db03 ~]# tar xf mysql-5.6.46.tar.gz
4.进入目录,生成
[root@db03 ~]# cd mysql-5.6.46/ [root@db03 mysql-5.6.46]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.46 \ -DMYSQL_DATADIR=/usr/local/mysql-5.6.46/data \ -DMYSQL_UNIX_ADDR=/usr/local/mysql-5.6.46/tmp/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS=all \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \ -DWITH_ZLIB=bundled \ -DWITH_SSL=system \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_EMBEDDED_SERVER=1 \ -DENABLE_DOWNLOADS=1 \ -DWITH_DEBUG=0
#若有报错说依赖不足,则再安装它需要的依赖,然后再次生成
5.编译和安装
[root@db03 mysql-5.6.46]# make && make install
#这里会比较慢,耐心等一下吧
6.做软链接
[root@db03 mysql-5.6.46]# ln -s /usr/local/mysql-5.6.46 /usr/local/mysql
7.创建用户
[root@db03 mysql-5.6.46]# useradd mysql -s /sbin/nologin -M
8.拷贝配置文件和启动文件
[root@db03 ~]# cd /usr/local/mysql/support-files/ [root@db03 support-files]# cp my-default.cnf /etc/my.cnf cp: overwrite ‘/etc/my.cnf’? y [root@db03 support-files]# cp mysql.server /etc/init.d/mysqld
9.初始化数据库
[root@db03 support-files]# cd /usr/local/mysql/scripts/
[root@db03 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
10.创建目录,授权mysql目录(否则会报错)
[root@db03 scripts]# mkdir /usr/local/mysql-5.6.46/tmp/ [root@db03 scripts]# chown -R mysql.mysql /usr/local/mysql [root@db03 scripts]# chown -R mysql.mysql /usr/local/mysql-5.6.46/
11.
[root@db03 scripts]# vim /usr/lib/systemd/system/mysqld.service [Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Install] WantedBy=multi-user.target [Service] User=mysql Group=mysql ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf LimitNOFILE = 5000 [root@db03 scripts]# systemctl daemon-reload [root@db03 scripts]# systemctl start mysqld
12.配置环境变量
[root@db03 scripts]# vim /etc/profile.d/mysql.sh export PATH=/usr/local/mysql/bin:$PATH [root@db03 scripts]# source /etc/profile
13.确认启动
[root@db03 scripts]# netstat -lntp tcp6 0 0 :::3306 :::* LISTEN 37659/mysqld
###注意,systemctl启动的mysql和 /etc/init.d/mysqld 启动的时不能互用的,用什么命令启动的就用什么关闭