centos7下源码安装mysql5.6_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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值