Centos7 源码安装mysql5.6

2020-08-21 00:40:46 浏览数 (1)

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

1.安装必要源

代码语言:javascript复制
yum -y install make bison-devel ncures-devel libaio perl-Data-Dumper net-tools bison bison-devel gcc-c   cmake ncurses ncurses-devel

2.解压、编译、安装

代码语言:javascript复制
[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.添加系统用户

代码语言:javascript复制
useradd mysql
chown -R mysql:mysql /usr/local/mysql56

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

代码语言:javascript复制
mkdir -p /data/mysqldb/data
chown -R mysql:mysql /data/mysqldb

初始化

代码语言:javascript复制
/usr/local/mysql56/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql56 --datadir=/data/mysqldb/data

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

代码语言:javascript复制
[root@s160 data]# cp /usr/local/mysql56/support-files/my-default.cnf  /etc/my.cnf

修改my.cnf文件

代码语言:javascript复制
# 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

代码语言:javascript复制
[root@s160 mysql]# mkdir -p /data/mysql/mysqllog
[root@s160 mysql]# chown -R mysql:mysql /data/mysql

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

代码语言:javascript复制
touch /usr/lib/systemd/system/mysqld.service

2)编辑mysqld.service

代码语言:javascript复制
[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)加入开机启动

代码语言:javascript复制
 systemctl enable mysqld

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

代码语言:javascript复制
export MYSQL_HOME=/usr/local/mysql56
export PATH=$PATH:$MYSQL_HOME/bin

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

代码语言:javascript复制
systemctl start mysqld.service

6)登录mysql并修改密码

代码语言:javascript复制
[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

0 人点赞