centos install mysql 5.6.40

官方文档 5.6

1 安装系统软件

yum -y install gcc gcc-c++ autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake

yum -y install gcc gcc-c++ make cmake bison-devel ncurses-devel

2 下载mysql源码

2.1 mysql官网下载mysql-5.6.40.tar.gz wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.40.tar.gz

2.2 或者从github上下载mysql源码 git clone https://github.com/mysql/mysql-server.git

3 编译mysql源码

# Preconfiguration setup
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql  
   or  useradd -r -g mysql -s /bin/bash mysql -d /home/mysql -m
# Beginning of source-build specific instructions
shell> tar zxvf mysql-VERSION.tar.gz
shell> cd mysql-VERSION
shell> mkdir bld
shell> cd bld
shell> cmake ..
shell> make
shell> make install
# End of source-build specific instructions
# Postinstallation setup
shell> cd /usr/local/mysql
shell> mkdir mysql-files
shell> chown mysql:mysql mysql-files
shell> chmod 750 mysql-files
shell> bin/mysqld --initialize --user=mysql 
shell> bin/mysql_ssl_rsa_setup              
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
不包含编译参数
-DWITH_READLINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \

编译参数

编译并安装

[root@szlinux02 mysql-5.7.18]# make -j `grep processor /proc/cpuinfo | wc -l`
[root@szlinux02 mysql-5.7.18]# make install
-j 参数表示根据 CPU 核数指定编译时的线程数,可以加快编译速度。默认为 1 个线程编译。

or

make
make install

4 安装配置MySQL

4.1 初始化数据库

cd /usr/local/mysql/scripts 
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

4.2 配置文件

#使用默认配置文件
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

vi /etc/my.cnf

[client]
port=3306 
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8

[mysqld]
user=mysql 
port=3306 
socket=/var/lib/mysql/mysql.sock 
basedir=/usr/local/mysql 
datadir=/usr/local/mysql/data/ 
open_files_limit=10240
character-set-server=utf8

[mysql]
#这个配置段设置启动MySQL服务的条件;在这种情况下,no-auto-rehash确保这个服务启动得比较快。 
no-auto-rehash
default-character-set=utf8

查看编码SHOW VARIABLES LIKE 'character%'

4.3 配置mysql服务

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
#让chkconfig管理mysql服务 
chkconfig --add mysql 
#开机启动 
chkconfig mysql on
# 启动mysql
service mysql start

4.4 把安装目录添加到环境变量中

echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile

4.5 配置用户密码和远程访问权限

mysql -uroot  
SET PASSWORD = PASSWORD('123456');
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
未测试:
mysqladmin -u root password '123456'   
注:也可运行安全设置脚本,修改MySQL用户root的密码,同时可禁止root远程连接,移除test数据库和匿名用户。 
/usr/local/mysql/bin/mysql_secure_installation 

4.6 配置防火墙

防火墙的3306端口默认没有开启,若要远程访问,需要开启这个端口

vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
:wq
service iptables restart

5 问题收集

5.1 问题:

Starting MySQL..The server quit without updating PID file ([FAILED]/mysql/Server03.mylinux.com.pid).
解决:
修改/etc/my.cnf 中datadir,指向正确的mysql数据库文件目录

5.2 问题:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解决:
新建一个链接或在mysql中加入-S参数,直接指出mysql.sock位置。
ln -s /usr/local/mysql/data/mysql.sock /tmp/mysql.sock

5.3 mysql_install_db

[root@g3 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
Installing MySQL system tables...2018-05-19 10:02:41 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-05-19 10:02:41 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-05-19 10:02:41 0 [Note] /usr/local/mysql//bin/mysqld (mysqld 5.6.40) starting as process 20528 ...
2018-05-19 10:02:41 20528 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-05-19 10:02:41 20528 [Note] InnoDB: The InnoDB memory heap is disabled
2018-05-19 10:02:41 20528 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-05-19 10:02:41 20528 [Note] InnoDB: Memory barrier is not used
2018-05-19 10:02:41 20528 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-05-19 10:02:41 20528 [Note] InnoDB: Using CPU crc32 instructions
2018-05-19 10:02:41 20528 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-05-19 10:02:41 20528 [Note] InnoDB: Completed initialization of buffer pool
2018-05-19 10:02:41 20528 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2018-05-19 10:02:41 20528 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2018-05-19 10:02:41 20528 [Note] InnoDB: Database physically writes the file full: wait...
2018-05-19 10:02:41 20528 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2018-05-19 10:02:41 20528 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2018-05-19 10:02:41 20528 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2018-05-19 10:02:41 20528 [Warning] InnoDB: New log files created, LSN=45781
2018-05-19 10:02:41 20528 [Note] InnoDB: Doublewrite buffer not found: creating new
2018-05-19 10:02:41 20528 [Note] InnoDB: Doublewrite buffer created
2018-05-19 10:02:41 20528 [Note] InnoDB: 128 rollback segment(s) are active.
2018-05-19 10:02:41 20528 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-05-19 10:02:41 20528 [Note] InnoDB: Foreign key constraint system tables created
2018-05-19 10:02:41 20528 [Note] InnoDB: Creating tablespace and datafile system tables.
2018-05-19 10:02:41 20528 [Note] InnoDB: Tablespace and datafile system tables created.
2018-05-19 10:02:41 20528 [Note] InnoDB: Waiting for purge to start
2018-05-19 10:02:42 20528 [Note] InnoDB: 5.6.40 started; log sequence number 0
2018-05-19 10:02:42 20528 [Note] Binlog end
2018-05-19 10:02:42 20528 [Note] InnoDB: FTS optimize thread exiting.
2018-05-19 10:02:42 20528 [Note] InnoDB: Starting shutdown...
2018-05-19 10:02:43 20528 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2018-05-19 10:02:43 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-05-19 10:02:43 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-05-19 10:02:43 0 [Note] /usr/local/mysql//bin/mysqld (mysqld 5.6.40) starting as process 20550 ...
2018-05-19 10:02:43 20550 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-05-19 10:02:43 20550 [Note] InnoDB: The InnoDB memory heap is disabled
2018-05-19 10:02:43 20550 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-05-19 10:02:43 20550 [Note] InnoDB: Memory barrier is not used
2018-05-19 10:02:43 20550 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-05-19 10:02:43 20550 [Note] InnoDB: Using CPU crc32 instructions
2018-05-19 10:02:43 20550 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-05-19 10:02:43 20550 [Note] InnoDB: Completed initialization of buffer pool
2018-05-19 10:02:43 20550 [Note] InnoDB: Highest supported file format is Barracuda.
2018-05-19 10:02:43 20550 [Note] InnoDB: 128 rollback segment(s) are active.
2018-05-19 10:02:43 20550 [Note] InnoDB: Waiting for purge to start
2018-05-19 10:02:43 20550 [Note] InnoDB: 5.6.40 started; log sequence number 1625977
2018-05-19 10:02:43 20550 [Note] Binlog end
2018-05-19 10:02:43 20550 [Note] InnoDB: FTS optimize thread exiting.
2018-05-19 10:02:43 20550 [Note] InnoDB: Starting shutdown...
2018-05-19 10:02:45 20550 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

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

Alternatively you can run: 

  /usr/local/mysql//bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; /usr/local/mysql//bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

New default config file was created as /usr/local/mysql//my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

[root@g3 scripts]# 
  • qq_43638135
    妲己再美究为妃: 博主没有想过自己接一些私活干吗?我现在还没毕业,但是我也确实听说外挂市场自动化游戏脚本市场挺火热的,并且报酬也很丰厚,但是具体的我也不是很清楚,求解答。 (1个月前 #47楼) 查看回复(2) 举报 回复
    22