标签:
最近想尝试下新版本的Mysql 5.7.10,于是开始尝试玩下。
在该次安装中,使用源码编译安装Mysql,编译器使用cmake。
这里选择的版本是mysql-5.7.10,cmake的版本是cmake-2.8.10.2
注:在下载源码包的时候,请注意选择Platform为“Source Code”。
环境:
[wh42@e3ddba11 mysql]$ sudo cat /etc/redhat-release
CentOS release 6.3 (Final)
[wh42@e3ddba11 mysql]$ uname -a
Linux e3ddba11 2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
下面是本次的安装步骤:
1.上传mysql-5.7.10.tar.gz和cmake-2.8.10.2.tar.gz文件到e3ddba11的/usr/local文件夹下。
2.在Centos上安装g++和ncurses_devel
[wh42@e3ddba11 local]$ sudo yum install gcc-c++
[wh42@e3ddba11 local]$ sudo yum install ncurses-devel
3.安装make
[wh42@e3ddba11 local]$ sudo yum install make
否则会报错: Cannot find appropriate Makefile processor on this system.
4.安装cmake
[wh42@e3ddba11 local]$ sudo tar -zxvf cmake-2.8.10.2.tar.gz
[wh42@e3ddba11 local]$ cd cmake-2.8.10.2
[wh42@e3ddba11 cmake-2.8.10.2]$ sudo ./configure
[wh42@e3ddba11 cmake-2.8.10.2]$ sudo make
[wh42@e3ddba11 cmake-2.8.10.2]$ sudo make install
5.安装boost,以便后面安装Mysql时使用.
在http://sourceforge.net/projects/boost/files/boost/1.59.0/中选择boost_1_59_0.tar.gz下载,然后上传到e3ddba11的/usr/local下
[wh42@e3ddba11 local]$ sudo tar -zxvf boost_1_59_0.tar.gz
6.将cmake加入到系统环境变量中
[wh42@e3ddba11 cmake-2.8.10.2]$ sudo vi /etc/profile
在最后添加两行;
PATH=/usr/local/cmake-2.8.10.2/bin:$PATH
export PATH
之后执行下面的代码使该修改生效。----这里不能直接执行sudo source /etc/profile会报错sudo: source: command not found
[root@e3ddba11 cmake-2.8.10.2]$ source /etc/profile
[wh42@e3ddba11 cmake-2.8.10.2]$ sudo -s
[root@e3ddba11 cmake-2.8.10.2]# source /etc/profile
此时,我们可以使用export来查看当前的PATH值
[wh42@e3ddba11 cmake-2.8.10.2]$ echo $PATH
6.创建Mysql的安装目录以及数据库文件存放的路径
[wh42@e3ddba11 cmake-2.8.10.2]$ sudo mkdir -p /usr/local/mysql
[wh42@e3ddba11 cmake-2.8.10.2]$ sudo mkdir -p /usr/local/mysql/data/
7.创建mysql用户以及对应用户组
[wh42@e3ddba11 cmake-2.8.10.2]$ sudo groupadd mysql
[wh42@e3ddba11 cmake-2.8.10.2]$ sudo useradd -r -g mysql mysql
8.编译安装mysql
[wh42@e3ddba11 cmake-2.8.10.2]$ cd /usr/local/
[wh42@e3ddba11 local]$ sudo tar -zxvf mysql-5.5.37.tar.gz
[wh42@e3ddba11 local]$ cd mysql-5.5.37
[wh42@e3ddba11 mysql-5.5.37]$
sudo cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_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 \
-DWITH_BOOST=/usr/local/boost_1_59_0
[wh42@e3ddba11 mysql-5.5.37]$ sudo make
[wh42@e3ddba11 mysql-5.5.37]$ sudo make install
9.验证mysql是否安装成功
[wh42@e3ddba11 mysql-5.5.37]$ cd /usr/local/mysql
[wh42@e3ddba11 mysql]$ ls
bin COPYING data docs include INSTALL-BINARY lib man mysql.sock mysql-test README scripts share sql-bench support-files
如果看到存在这些文件或者文件夹,那么证明mysql安装成功。
10.设置mysql目录的权限
[wh42@e3ddba11 mysql]$ sudo chown -R mysql:mysql /usr/local/mysql
[wh42@e3ddba11 mysql]$ sudo chown -R mysql:mysql data
11.创建系统数据库的表
[wh42@e3ddba11 mysql]$ cd /usr/local/mysql/bin
[wh42@e3ddba11 mysql]$ sudo ./mysqld --initialize --user=mysql
12.my.cnf配置文件产生
[wh42@e3ddba11 bin]$ sudo cp ../support-files/my-default.cnf /etc.my.cnf
13.将mysql服务设置为自动开启
[wh42@e3ddba11 bin]$ sudo cp ../support-files/mysql.server /etc/init.d/mysqld
[wh42@e3ddba11 bin]$ sudo chkconfig --add mysqld && chkconfig mysqld on
14.设置环境变量
[wh42@e3ddba11 mysql]$ sudo vi /root/.bash_profile
修改PATH为:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
之后执行下面的代码使该修改生效。----这里不能直接执行sudo source /etc/profile会报错sudo: source: command not found
[wh42@e3ddba11 mysql]$ source /root/.bash_profile
[wh42@e3ddba11 mysql]$ sudo -s
[root@e3ddba11 mysql]# source /root/.bash_profile
同时也将mysql的路径加入到/etc/profile下。
[wh42@e3ddba11 mysql]$ sudo vi /etc/profile
在最后添加两行
PATH=/usr/local/mysql/bin:$PATH
export PATH
[wh42@e3ddba11 mysql]$ source /etc/profile
[wh42@e3ddba11 mysql]$ sudo -s
[root@e3ddba11 mysql]# source /etc/profile
15.开启mysql服务
[wh42@e3ddba11 bin]$ sudo ./mysqld_safa --user=mysql --skip-grant-tables &
16.在另外窗口新开session,进入mysql。修改root的密码。
[wh42@e3ddba11 bin]$ mysql -uroot
mysql> update mysql.user set authentication_string=password(‘wison‘) where user=‘root‘ and host=‘localhost‘
-> ;
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
16.进入mysql:
[wh42@e3ddba11 ~]$ mysql -uroot -pwison
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.10
Copyright (c) 2000, 2015, 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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user ‘root‘@‘localhost‘ identified by ‘wison‘;
Query OK, 0 rows affected (0.00 sec)
到此,mysql已经安装完毕。
标签:
原文地址:http://www.cnblogs.com/Wison-Ho/p/5036663.html