Mysql编译安装

mysql安装

关闭防火墙和selinux

一、编译安装mysql5.7

1、清理安装环境:
# yum erase mariadb mariadb-server mariadb-libs mariadb-devel -y
# userdel -r mysql
# rm -rf /etc/my*
# rm -rf /var/lib/mysql
2、创建mysql用户
[root@mysql-server ~]# useradd -r mysql -M -s /bin/nologin
-M 不创建用户的家目录
3、从官网下载tar包

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.27.tar.gz

4、安装编译工具
# yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make glibc automake autoconf
# yum -y install cmake
5、创建mysql目录
[root@mysql-server ~]# mkdir -p /usr/local/{data,mysql,log}
6、解压
[root@mysql-server ~]# tar xzvf mysql-boost-5.7.27.tar.gz -C /usr/local/
7、编译安装
cd 解压的mysql目录
[root@mysql-server ~]# cd /usr/local/mysql-5.7.27/
[root@mysql-server mysql-5.7.27]# cmake . \
-DWITH_BOOST=boost/boost_1_59_0/ \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DINSTALL_MANDIR=/usr/share/man \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1

参数详解:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \   安装目录
-DSYSCONFDIR=/etc \   配置文件存放 (默认可以不安装配置文件)
-DMYSQL_DATADIR=/usr/local/mysql/data \   数据目录   错误日志文件也会在这个目录
-DINSTALL_MANDIR=/usr/share/man \     帮助文档 
-DMYSQL_TCP_PORT=3306 \     默认端口
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \  sock文件位置,用来做网络通信的,客户端连接服务器的时候用
-DDEFAULT_CHARSET=utf8 \    默认字符集。字符集的支持,可以调
-DEXTRA_CHARSETS=all \   扩展的字符集支持所有的
-DDEFAULT_COLLATION=utf8_general_ci \  支持的
-DWITH_READLINE=1 \    上下翻历史命令
-DWITH_SSL=system \    使用私钥和证书登陆(公钥)  可以加密。 适用与长连接。坏处:速度慢
-DWITH_EMBEDDED_SERVER=1 \   嵌入式数据库
-DENABLED_LOCAL_INFILE=1 \    从本地倒入数据,不是备份和恢复。
-DWITH_INNOBASE_STORAGE_ENGINE=1  默认的存储引擎,支持外键

[root@mysql-server mysql-5.7.27]# make && make install
如果安装出错,想重新安装:
    不用重新解压,只需要删除安装目录中的缓存文件CMakeCache.txt

需要很长时间!大约半小时

8、初始化
[root@mysql-server mysql-5.7.27]# cd /usr/local/mysql
[root@mysql-server mysql]# chown -R mysql.mysql .
[root@mysql-server mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data     ---初始化完成之后,一定要记住提示最后的密码用于登陆或者修改密码

初始化,只需要初始化一次

设置环境变量
[root@localhost mysql]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
[root@localhost mysql]# source /etc/profile
[root@localhost mysql]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

[root@mysql-server ~]# vim /etc/my.cnf  --如果打开文件有内容将文件中所有内容注释掉,在里添加如下内容
[client]
port = 3306                   # 默认连接端口
socket = /tmp/mysql.sock      # 用于本地连接的socket套接字
default-character-set = utf8  # 编码

[mysqld]
port = 3306                   # 服务端口号,默认3306
user = mysql                  # mysql启动用户
basedir = /usr/local/mysql    #指定安装目录
datadir = /usr/local/mysql/data  #指定数据存放目录
socket = /tmp/mysql.sock    # 为MySQL客户端程序和服务器之间的本地通讯指定一个套接字文件
character_set_server = utf8   # 数据库默认字符集
9、启动MySQL
[root@mysql-server ~]# cd /usr/local/mysql
[root@mysql-server mysql]# ./bin/mysqld_safe --user=mysql &

启动之后再按一下回车!即可后台运行

10、登录MySQL
[root@mysql-server mysql]# /usr/local/mysql/bin/mysql -uroot -p'GP9TKGgY9i/8'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.27

Copyright (c) 2000, 2019, 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> exit
11、启动MySQL数据库
  • 拷贝启动脚本到/etc/init.d/目录下,并改名mysqld
[root@qfedu.com mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@qfedu.com mysql]# ls -l /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10588 Aug 1 18:33 /etc/init.d/mysqld
  • 重新加载系统服务,将MySQL数据库加入开机自启动
[root@localhost mysql]# systemctl daemon-reload
[root@localhost mysql]# chkconfig mysqld on  #设置开机启动
  • 启动MySQL数据库,并检查端口监听状态
[root@localhost mysql]# /etc/init.d/mysqld stop   --停止mysqld
# 或者
[root@localhost mysql]# /etc/init.d/mysqld start  --启动mysqld
Starting MySQL. SUCCESS! 

[root@localhost mysql]# netstat -lntp | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      16744/mysqld
12、给数据库修改密码
[root@localhost ~]# /usr/local/mysql/bin/mysqladmin -uroot -p'GP9TKGgY9i/8' password 'Wzhmsy980414'
[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot -p'Wzhmsy980414'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.27

Copyright (c) 2000, 2019, 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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值