mysql 5.6 编译安装

添加用户 授权目录

[root@b11 tools]# useradd mysql
[root@b11 tools]# mkdir -p /disk1/{mysql,mysql_data}
[root@b11 tools]# chown -R mysql. /disk1

下载MySQL的源码包

wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.37.tar.gz

[root@b11 tools]# ll
total 1152520
drwxr-xr-x 35 7161 31415 4096 Jul 10 14:23 mysql-5.6.37
-rw-r--r-- 1 root root 32200158 Jun 2 2017 mysql-5.6.37.tar.gz
[root@b11 tools]#

安装编译代码需要的包

[root@b11 tools]# yum -y install make gcc-c++ cmake bison-devel ncurses-devel

[root@b11 tools]# cd mysql-5.6.37/

cmake -DCMAKE_INSTALL_PREFIX=/disk1/mysql   #安装路径
-DMYSQL_UNIX_ADDR=/disk1/mysql/mysql.sock   #连接数据库socket路径
-DDEFAULT_CHARSET=utf8   #字符集
-DDEFAULT_COLLATION=utf8_general_ci   #

-DWITH_MYISAM_STORAGE_ENGINE=1   #支持MyIASM 引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1   #支持InnoDB 引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1   #
-DWITH_BLACKHOLE_STORAGE_ENGINE=1   #
-DENABLED_LOCAL_INFILE=1   #允许从本地导入数据
-DMYSQL_DATADIR=/disk1/mysql_data   #数据存储目录
-DMYSQL_TCP_PORT=3306 #端口

执行完cmake之后、执行make和make install 整个过程时间较长、请稍等!

开始初始化

[root@b11 scripts]# ./mysql_install_db --user=mysql --datadir=/disk1/mysql_data --basedir=/disk1/mysql
[root@b11 mysql]# chown -R mysql. my.cnf
[root@b11 mysql]# cd support-files/
[root@b11 support-files]# ll
total 32
-rwxr-xr-x 1 mysql mysql 1153 Jul 10 14:02 binary-configure
-rw-r--r-- 1 mysql mysql 773 Jun 3 2017 magic
-rw-r--r-- 1 mysql mysql 1126 Jul 10 14:02 my-default.cnf
-rwxr-xr-x 1 mysql mysql 1061 Jul 10 14:02 mysqld_multi.server
-rwxr-xr-x 1 mysql mysql 874 Jul 10 14:02 mysql-log-rotate
-rwxr-xr-x 1 mysql mysql 10541 Jul 10 14:02 mysql.server
[root@b11 support-files]# cp ./mysql.server /etc/init.d/mysql
[root@b11 support-files]# chmod +x /etc/init.d/mysql

[root@b11 support-files]# /etc/init.d/mysql start #启动报错
Starting MySQL.Logging to '/var/log/mysql/mysql.log'.
170916 12:28:00 mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
ERROR! The server quit without updating PID file (/var/run/mysql/mysql.pid).
[root@b11 support-files]# mkdir /var/lib/mysql
[root@b11 support-files]# mkdir /var/log/mysql/ -p
[root@b11 support-files]# chown -R mysql.mysql /var/log/mysql
[root@b11 support-files]# mkdir /var/run/mysql
[root@b11 support-files]# chown mysql /var/run/mysql
[root@b11 support-files]# chown -R mysql.mysql /var/lib/mysql/
[root@b11 support-files]# /etc/init.d/mysql start #再次启动

[root@b11 mysql]# /etc/init.d/mysql status #启动报错
ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists #目录下文件删除
[root@b11 mysql]# /etc/init.d/mysql status
ERROR! MySQL is not running
[root@b11 mysql]# /etc/init.d/mysql start
Starting MySQL.Logging to '/disk1/mysql_data/b11.err'.
. SUCCESS!

[root@b11 mysql]# ps -aux|grep mysql
root 88943 0.0 0.3 115444 3052 ? S 14:43 0:00 /bin/sh /disk1/mysql/bin/mysqld_safe --datadir=/disk1/mysql_data --pid-file=/disk1/mysq
mysql 89040 1.6 45.1 1296368 450864 ? Sl 14:43 0:00 /disk1/mysql/bin/mysqld --basedir=/disk1/mysql --datadir=/disk1/mysql_data --plugin-dirplugin --user=mysql --log-error=b11.err --pid-file=/disk1/mysql_data/b11.pid
root 89103 0.0 0.2 112716 2252 pts/2 R+ 14:43 0:00 grep --color=auto mysql
[root@b11 mysql]# netstat -lntup|grep mysql
tcp6 0 0 :::3306 :::* LISTEN 89040/mysqld

设置mysql 环境变量

[root@b11 mysql]# cat /etc/profile
export MYSQL_HOME=/disk1/mysql
export PATH=$PATH:$MYSQL_HOME/bin

[root@b11 mysql]# source /etc/profile

修改数据库密码

/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h 192.168.56.11 password 'new-password'

登录数据库

[root@b11 mysql]# mysql -uroot -p -h127.0.0.1
Enter password: #输入设置的密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.37 Source distribution

Copyright (c) 2000, 2017, 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>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)

配置文件

[root@b11 mysql]# egrep "^[[|a-Z]" my.cnf
[mysql]
socket=/disk1/mysql/mysql.sock
default-character-set=utf8
[mysqld]
skip-grant-tables
explicit_defaults_for_timestamp=true
skip-name-resolve
port = 3306
socket=/disk1/mysql/mysql.sock
basedir=/disk1/mysql
datadir=/disk1/mysql_data
max_connections = 200
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
log-error=/disk1/mysql_data/b11.err
pid-file=/disk1/mysql_data/b11.pid
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[root@b11 mysql]#

猜你喜欢

转载自www.cnblogs.com/fengmeng1030/p/9289612.html