Mysql5.6.26源码编译安装

安装依赖包ncurses-devel和编译工具cmake

[root@shenxiang67 ~]# yum install ncurses-devel cmake –y

建立mysql执行账户和数据目录

[root@shenxiang67 ~]# useradd -u 3366 -s /sbin/nologin mysql 
[root@shenxiang67 ~]# mkdir /data

解压源码包并从新配置安装信息

  • 解压源码包与配置
[root@shenxiang67 download]# tar zxf mysql-5.6.26.tar.gz 
[root@shenxiang67 download]# cd mysql-5.6.26
[root@shenxiang67 mysql-5.6.26]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/data \
-DMYSQL_USER=mysql
  • 参数说明

-DCMAKE_INSTALL_PREFIX                  # 数据文件存放目录
-DMYSQL_UNIX_ADDR                        # sock文件路径
-DDEFAULT_CHARSET                          # 默认字符集
-DDEFAULT_COLLATION                      # 默认字符校对
-DWITH_EXTRA_CHARSETS                  # 扩展字符支持 默认all
-DWITH_storage_STORAGE_ENGINE    # 存储引擎的支持,默认支持MyISAM,MERGE,MEMORY,CVS存储引擎
-DENABLED_LOCAL_INFILE=1             # 启用加载本地数据
-DMYSQL_DATADIR                            # 数据存放目录
-DMYSQL_USER                                   # mysql运行用户mysql

  • 扩展

-DWITH_PARTITION_STORAGE_ENGINE=1      #支持分区表
-DINSTALL_LIBDIR=dir_name Library               #库目录
-DSYSCONFDIR=dir_name                                #The default my.cnf option file directorysql

编译和安装

[root@shenxiang67 mysql-5.6.26]# echo $? 
0 
[root@shenxiang67 mysql-5.6.26]# make -j 4 && make install

初始设置mysql服务

  • 受权用户
[root@shenxiang67 mysql-5.6.26]# chown -R mysql:mysql /usr/local/mysql/
[root@shenxiang67 mysql-5.6.26]# chown -R mysql:mysql /data
[root@shenxiang67 mysql-5.6.26]# chmod 1777 /tmp
  • 配置环境变量
[root@shenxiang67 mysql-5.6.26]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile 
[root@shenxiang67 mysql-5.6.26]# source !$ 
source /etc/profile
  • 建立配置文件和启动脚本,并开机自启
[root@shenxiang67 mysql-5.6.26]# cp support-files/my-default.cnf /etc/my.cnf   #添加配置文件 
cp: overwrite `/etc/my.cnf'? y 
[root@shenxiang67 mysql-5.6.26]# cp support-files/mysql.server /etc/init.d/mysqld   #添加启动脚本 
[root@shenxiang67 mysql-5.6.26]# chmod +x /etc/init.d/mysqld   #给脚本添加执行权限 
[root@shenxiang67 mysql-5.6.26]# vim /etc/init.d/mysqld   #修改服务启动脚本的两个参数 
basedir=/usr/local/mysql   #MySQL安装目录 
datadir= /data   #数据存放目录 
[root@shenxiang67 mysql-5.6.26]# chkconfig mysqld on   #添加开机启动

初始化数据库

[root@shenxiang67 mysql-5.6.26]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data --user=mysql
 
Installing MySQL system tables... 
OK 
Filling help tables... 
OK 
…..省略

启动mysql服务

[root@shenxiang67 mysql-5.6.26]# /etc/init.d/mysqld start 
Starting MySQL.. SUCCESS!

注:必须初始化数据库才可去启动,不然报错。数据库

初始化安全配置

[root@shenxiang67 mysql-5.6.26]# mysql_secure_installation #安全初始化配置
 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL 
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! 
In order to log into MySQL to secure it, we'll need the current 
password for the root user. If you've just installed MySQL, and 
you haven't set the root password yet, the password will be blank, 
so you should just press enter here. 

Enter current password for root (enter for none): 初始无密码 直接按空格 
OK, successfully used password, moving on... 

Setting the root password ensures that nobody can log into the MySQL 
root user without the proper authorisation. 
Set root password? [Y/n] y 建立超级用户密码 
New password: 
Re-enter new password: 
Password updated successfully! 
Reloading privilege tables.. 
... Success! 

By default, a MySQL installation has an anonymous user, allowing anyone 
to log into MySQL without having to have a user account created for 
them. This is intended only for testing, and to make the installation 
go a bit smoother. You should remove them before moving into a 
production environment. 
Remove anonymous users? [Y/n] y 删除匿名用户 
... Success! 

Normally, root should only be allowed to connect from 'localhost'. This 
ensures that someone cannot guess at the root password from the network. 
Disallow root login remotely? [Y/n] y 拒绝超级用户远程登录 
... Success! 

By default, MySQL comes with a database named 'test' that anyone can 
access. This is also intended only for testing, and should be removed 
before moving into a production environment. 
Remove test database and access to it? [Y/n] y 删除测试数据库和访问吗? 
- Dropping test database... 
... Success! 
- Removing privileges on test database... 
... Success! 

Reloading the privilege tables will ensure that all changes made so far 
will take effect immediately. 
Reload privilege tables now? [Y/n] y 如今从新加载权限表吗? 
... Success! 

Cleaning up... 
All done! If you've completed all of the above steps, your MySQL 
installation should now be secure.
 
Thanks for using MySQL!

登录测试

[root@shenxiang67 mysql-5.6.26]# mysql -uroot -p 
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 9 
Server version: 5.6.26-log Source distribution 
Copyright (c) 2000, 2013, 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> select user,host from mysql.user; 全部命令必须以“;”结束而去执行 
+------+-----------+ 
| user | host | 
+------+-----------+ 
| root | 127.0.0.1 | 
| root | ::1 | 
| root | localhost | 
+------+-----------+ 
3 rows in set (0.00 sec)
 
mysql>


常见问题

  • 问题1

Starting MySQL.. ERROR! The server quit without updating PID file (/data/shenxiang66.pid).
出如今这问题的缘由是:无初始化数据库而启动mysql服务vim


解决:从新初始化数据库便可安全

  • 问题2

Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)bash


解决:
pkill mysqld 干掉mysql进程
rm -rf /data/* 删除data中全部数据
从新初始化工具

相关文章
相关标签/搜索