Centos7 源码安装mysql5.6

时间:2022-07-23
本文章向大家介绍Centos7 源码安装mysql5.6,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

mysql下载 谷歌 mysql-》community-》mysql community server-》mysql community server 5.6-》Select Operating System-》source code

1.安装必要源

yum -y install make bison-devel ncures-devel libaio perl-Data-Dumper net-tools bison bison-devel gcc-c++ cmake ncurses ncurses-devel

2.解压、编译、安装

[root@s160 opt]# tar zxvf mysql-5.6.41.tar.gz
[root@s160 mysql-5.6.41]# cd mysql-5.6.41/
[root@s160 mysql-5.6.41]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql56
[root@s160 mysql-5.6.41]# make && make install

3.添加系统用户

useradd mysql
chown -R mysql:mysql /usr/local/mysql56

4.创建/data/mysqldb/data目录,修改权限

mkdir -p /data/mysqldb/data
chown -R mysql:mysql /data/mysqldb

初始化

/usr/local/mysql56/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql56 --datadir=/data/mysqldb/data

5.添加并修改/etc/my.cnf文件

[root@s160 data]# cp /usr/local/mysql56/support-files/my-default.cnf  /etc/my.cnf

修改my.cnf文件

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
basedir = /data/mysql
datadir = /data/mysqldb/data
log-error=/data/mysql/mysqllog/logerr.log
tmpdir=/data/mysqldb
pid-file=/data/mysql/mysql.pid
socket=/home/mysql/mysqld.sock
lc_messages_dir=/usr/local/mysql56/share

port=3306
server_id=1

[client]
socket=/home/mysql/mysqld.sock

创建目录/data/mysql/mysqllog

[root@s160 mysql]# mkdir -p /data/mysql/mysqllog
[root@s160 mysql]# chown -R mysql:mysql /data/mysql

6.添加开机启动 1)将mysql加入到systemctl管理

touch /usr/lib/systemd/system/mysqld.service

2)编辑mysqld.service

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://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/mysql56/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
#Restart=on-failure
#RestartPreventExitStatus=1
#PrivateTmp=false

3)加入开机启动

 systemctl enable mysqld

4)配置mysql环境变量/etc/profile

export MYSQL_HOME=/usr/local/mysql56
export PATH=$PATH:$MYSQL_HOME/bin

配置生效 source /etc/profile 5)启动mysql

systemctl start mysqld.service

6)登录mysql并修改密码

[root@s160 data]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.6.41-log Source distribution

Copyright (c) 2000, 2018, 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> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('1234@abcd');
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye