mysql5.7.17一直号称世界上最好的mysql
那么就在阿里云主机linux安装它(采用的源码安装mysql5.7.17)
我在阿里云主机上安装它
连接阿里云主机
进入,跟我们自己装的虚拟机一毛一样
[root@iZ2ze5uydxlvgxknyk9xx9Z ~]# cd /usr/local/src
下载mysql5.7.17
[root@iZ2ze5uydxlvgxknyk9xx9Z src]# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17.tar.gz
如果此地址不行,请用清华大学镜像站下载:wget https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.17.tar.gz
下载安装mysql5.7.17所依赖包boost
[root@iZ2ze5uydxlvgxknyk9xx9Z src]# https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-boost-5.7.17.tar.gz
解压mysql和boost:
[root@iZ2ze5uydxlvgxknyk9xx9Z src]# tar vfxz mysql-5.7.17.tar.gz
[root@iZ2ze5uydxlvgxknyk9xx9Z src]# tar vfxz mysql-boost-5.7.17.tar.gz
都在mysql-5.7.17里面了
[root@iZ2ze5uydxlvgxknyk9xx9Z src]# cd mysql-5.7.17
移动boost包到/usr/local
[root@iZ2ze5uydxlvgxknyk9xx9Z src]# mv /usr/local/src/mysql-5.7.17/boost /usr/local
mysql5.7不是configure,make,make & make install安装,而是最新的cmake编译(个人觉得比make编译好)方式
安装mysql需要添加一个mysql用户和mysql组
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql-5.7.17]# groupadd mysql
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql-5.7.17]# useradd -g mysql mysql -s /bin/false
说明一下, 指定 /bin/false是为了安全问题,创建的mysql查询如下,这样它的权限仅限于执行我们安装mysql了
创建mysql和data文件夹
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql-5.7.17]# cd /usr/local
[root@iZ2ze5uydxlvgxknyk9xx9Z local]# mkdir /usr/local/mysql
[root@iZ2ze5uydxlvgxknyk9xx9Z local]# cd mysql
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql]# mkdir /usr/local/mysql/data
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql]# cd ..
查看mysql的权限
更改权限给mysql
[root@iZ2ze5uydxlvgxknyk9xx9Z local]# chown -R mysql:mysql /usr/local/mysql
[root@iZ2ze5uydxlvgxknyk9xx9Z local]# cd mysql
[root@iZ2ze5uydxlvgxknyk9xx9Z local]# cd /usr/local/src/mysql-5.7.17
为了防止后面因为少某个组件而发生问题,集中安装一下,下面这些长命令需要复制到你的编辑器中,弄成一行,注意空格,非常重要
[root@iZ2ze5uydxlvgxknyk9xx9Z local]# yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers gd gd2 gd-devel gd2-devel perl-CPAN pcre-devel
进入mysql-5.7.17目录
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql-5.7.17]# cd usr/local/src/mysql-5.7.17
只要在cmake编译之前存在CMakeCache.txt这个文件就删除,不管什么时候
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql-5.7.17]# rm -rf CMakeCache.txt
*************************************************************
mysql5.7系列需安装boost库,所以加上boost参数,-DDOWNLOAD_BOOST=1 -DWITH_BOOST=配置路径
前面是1代表下载,在cmake时会自动帮我们下载,不下载设为0,这里我们是下载,因为默认让他帮我们下载太慢了,后面是配置下载存放的路径(注意路径要存在)
boost包之前解压放在了/usr/local/src/boost里面
*************************************************************
如果cmake没有的话,就安装cmake
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql-5.7.17]# yum install cmake
cmake编译
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql-5.7.17]# cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DENABLED_LOCAL_INFILE=1
-DMYSQL_DATADIR=/usr/local/mysql/data
-DMYSQL_USER=mysql
-DMYSQL_TCP_PORT=3306
-DENABLE_DOWNLOADS=0
-DWITH_BOOST=/usr/local/boost
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql-5.7.17]# make && make install
**************************************************************************************************************************************************************************************
如果出现如下问题的话,是由于计算机内存的问题,没钱,阿里云买的内存小了点,塞满了,被干掉
(阿里云内存太小了,嗯,好坑哦,买的阿里云主机内存大的同学可以忽略这个)
截取网友的处理办法
敲如下命令增加swap分区
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql-5.7.17]# dd if=/dev/zero of=/swapfile bs=1k count=2048000
2048000+0 records in
2048000+0 records out
2097152000 bytes (2.1 GB) copied, 53.9022 s, 38.9 MB/s
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql-5.7.17]# mkswap /swapfile
mkswap: /swapfile: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 2047996 KiB
no label, UUID=b6ae6ff6-2f42-48f8-b097-d205ddc68802
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql-5.7.17]# swapon /swapfile
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql-5.7.17]# swapon -s
Filename Type Size Used Priority
/swapfile file 2047996 0 -1
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql-5.7.17]# echo "/var/swapfile swap swap defaults 0 0" >> /etc/fstab
ok,创建swap分区成功,安装完mysql,可以删掉swap分区,执行命令就好
swapoff /swapfile
rm -fr /swapfile
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql-5.7.17]# make && make install
**************************************************************************************************************************************************************************************
等待时间比较长(中间有警告错误,不用管,电脑差的话大概2小时)。。。。。。。。。。。。。
艰难的等待,终于编译并且安装成功,喜大泪奔
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql-5.7.17]# cd /usr/local/mysql
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql]# chown -R mysql:mysql /usr/local/mysql
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql]# cd support-files
这是mysql的配置文件,my.cnf,类似于php.ini
[root@iZ2ze5uydxlvgxknyk9xx9Z support-files]# cp my-default.cnf /etc/my.cnf
[root@iZ2ze5uydxlvgxknyk9xx9Z support-files]# vim /etc/my.cnf
改为
mysql5.7废弃了.scripts/mysql_install_db的初始化,改用其它的了
[root@iZ2ze5uydxlvgxknyk9xx9Z bin]# ./mysqld --defaults-file=/etc/my.cnf --datadir=/usr/local/mysql/data --initialize --user=mysql
出现如下
data目录里有东西,先把它给干掉
[root@iZ2ze5uydxlvgxknyk9xx9Z support-files]# cd /usr/local/mysql
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql]# rm -rf data
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql]# mkdir data
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql]# chown -R mysql:mysql data
mysql初始化
[root@iZ2ze5uydxlvgxknyk9xx9Z mysql]# cd /usr/local/mysql/bin
[root@iZ2ze5uydxlvgxknyk9xx9Z bin]# ./mysqld --defaults-file=/etc/my.cnf --datadir=/usr/local/mysql/data --initialize --user=mysql
执行完会出现如下,那是数据库的临时密码,把他记住啦,不要丢,待会登录要用
[root@iZ2ze5uydxlvgxknyk9xx9Z bin]# cd /usr/local/mysql/support-files
[root@iZ2ze5uydxlvgxknyk9xx9Z support-files]# ln -s /tmp/mysql.sock /usr/local/mysql.sock
[root@iZ2ze5uydxlvgxknyk9xx9Z support-files]# ./mysql.server start
启动成功
登录mysql
[root@iZ2ze5uydxlvgxknyk9xx9Z bin]# ./mysql -u root -p
登录成功
要求我们更改初始密码,因为那个密码是系统给的
输入exit退出mysql
更改密码
[root@iZ2ze5uydxlvgxknyk9xx9Z bin]# ./mysqladmin -uroot -p password 123456
输入初始密码,更改成功
再次登录
[root@iZ2ze5uydxlvgxknyk9xx9Z bin]# ./mysql -u root -p
登录成功!
至此,mysql5.7.17源码安装成功!
下面是转的网友的二进制安装,这个比较快而且方便
1.mysql5.7.17安装在/usr/local/mysql目录里面,也可以安装在其他地方 (安装包最好与Linux系统一样,eg;32位的就是“mysql-5.7.17-linux-glibc2.5-i686.tar.gz”,官网可下载)
mkdir /usr/local/MySQL
2.解压并复制
- tar -xvf mysql-5.7.17-linux-glibc2.5-i686.tar.gz
- mv mysql-5.7.17-linux-glibc2.5-i686.tar.gz/* /usr/local/mysql/
3.创建data目录(很重要!)
- mkdir /usr/local/mysql/data
4.创建mysql用户和修改权限
- groupadd mysql
- chown -R mysql.mysql /usr/local/mysql/
5.初始化数据
- [root@localhost mysql] ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
- 2016-01-20 02:47:35 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
- 2016-01-20 02:47:45 [WARNING] The bootstrap log isn't empty:
- 2016-01-20 02:47:45 [WARNING] 2016-01-19T18:47:36.732678Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
- 2016-01-19T18:47:36.750527Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
- 2016-01-19T18:47:36.750560Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
6. 复制配置文件到 /etc/my.cnf
- cp -a ./support-files/my-default.cnf /etc/my.cnf (选择y)
7. mysql的服务脚本放到系统服务中
- cp -a ./support-files/mysql.server /etc/init.d/mysqld
- 修改my.cnf文件 (vim /etc/my.cnf)
- # These are commonly set, remove the # and set as required.
- basedir = /usr/local/mysql
- datadir = /usr/local/mysql/data
- port = 3306
- # server_id = .....
- socket = /tmp/mysql.sock
- character-set-server = utf8
- # 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
8.启动mysql
- service mysqld start
- ps -ef #查看是启动
9.查看初始化自动生成的密码: cat /root/.mysql_secret (记住并复制下来,等会登陆mysql需要)
10.进入mysql:bin/mysql -uroot -p (把刚刚复制的密码粘贴上来)
11.登录后重置root密码
mysql> SET PASSWORD FOR 'root'@localhost = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
#此实验本人已验证没问题,是参照很多IT朋友的博客总结来的,敬礼!