mysqld_safe
1.0、参考

参数说明:

参数说明
--basedir=path
--builddir=path
--datadir=path
--ldata=path
--srcdir=path
--defaults-file=name默认的配置文件
--user=name指定用户

执行如下命令:

BASE_DIR=/home/leleliu008/bin/mysql-5.6.20-linux-glibc2.5-x86_64
sudo ./mysql_install_db --basedir=${BASE_DIR} --datadir=${BASE_DIR}/data --defaults-file=${BASE_DIR}/my.cnf --user=root

这里可能会遇到这个错误:

/usr/local/mysql3306/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

需要安装libaio-dev,使用如下命令安装:

sudo apt-get install -y libaio-dev

执行完查看,如下:

发现生成了my.cnf配置文件。内容如下:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

可以修改此文件中的如下:

basedir = /home/leleliu008/bin/mysql-5.6.20-linux-glibc2.5-x86_64/
datadir = /home/leleliu008/bin/mysql-5.6.20-linux-glibc2.5-x86_64/data/
port = 3306
# server_id = .....
socket = /tmp/mysql.sock

log-error=/home/leleliu008/bin/mysql-5.6.20-linux-glibc2.5-x86_64/error.log
user=root
explicit_defaults_for_timestamp=true

启动MySQL服务:

#!/bin/sh
MYSQL_HOME=/home/leleliu008/bin/mysql-5.6.20-linux-glibc2.5-x86_64
cd ${MYSQL_HOME}/bin
sudo ./mysqld --defaults-file=${MYSQL_HOME}/my.cnf &

查看mysql服务是否启动:

netstat -nat

mysql默认端口号为3306,以上信息中出现3306端口号,则启动成功