1:下载mysql  

  http://dev.mysql.com/downloads/mysql/#downloads   platfrom :source code

2:先安装cmake(mysql5.5以后是通过cmake来编译的)

    yum安装    

   

yum install cmake


3:
mkdir /usr/local/mysql                  //安装目录
mkdir /mnt/resource/mysqldate        //数据存放目录
4:  
groupadd mysql
useradd -r -g mysql mysql

5:  

tar -zxvf mysql.5.6.14.tar.gz
cd mysql.5.6.14.tar.gz

6 :  

mkdir build&& cd build
       cmake ..
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/mnt/resource/mysqldate
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DEXTRA_CHARSETS=all
-DENABLED_LOCAL_INFILE=1


参数说明

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql        //安装目录

-DINSTALL_DATADIR=/usr/local/mysql/data         //数据库存放目录

-DDEFAULT_CHARSET=utf8                        //使用utf8字符

-DDEFAULT_COLLATION=utf8_general_ci            //校验字符

-DEXTRA_CHARSETS=all                            //安装所有扩展字符集

-DENABLED_LOCAL_INFILE=1                        //允许从本地导入数据

重新编译时,需要清除旧的对象文件和缓存信息。

#make 之后

# make clean

# rm -f CMakeCache.txt

# rm -rf /etc/my.cnf

安装过程中会报很多错,大体能在一下网站解决http://blog.chinaunix.net/uid-13954789-id-3432115.html

================================================================================================

安装过程并不顺利,遇到好几次错误
1.没有安装 gcc 和 gcc-c++,执行cmake报如下错误:
==================================================
[root@ice mysql-5.5.27]# cmake .
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error: your C compiler: "CMAKE_C_COMPILER-NOTFOUND" was not found.   Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found.   Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
.
-- Configuring incomplete, errors occurred!
==================================================
解决方法:安装gcc和gcc-c++
yum install gcc
yum install gcc-c++
#删除cache文件,不删除还会报错
rm CMakeCache.txt
cmake .
2.编译快结束时,又报如下错误:
Warning: Bison executable not found in PATH
解决方法:安装bison
yum install bison
rm CMakeCache.txt
cmake .
#编译通过
make && make install
#执行时间比较长

3.无法启动mysql
bin/mysqld_safe --user=mysql & 无法启动
解决方法:
再执行一次scripts/mysql_install_db --user=mysql
为什么会这样,原因不明

====================================================================

下载的版本有问题。

正确的版本如下:

1、http://dev.mysql.com/downloads/mysql/

2、选择 MySQL Community Server

3、    mysql5.6.14 安装笔记_mysql


4、mysql5.6.14 安装笔记_cnetos6.4 _02

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++




7:配置

(1)设置目录权限

[root@pacteralinux mysql-5.6.14]# cd /usr/local/mysql/
[root@pacteralinux mysql]# chown -R root:mysql . //把当前目录中所有文件的所有者所有者设为root,所属组为mysql
[root@pacteralinux mysql]# cd /mnt/resource/data/
[root@pacteralinux data]# chown -R mysql:mysql  .
[root@pacteralinux data]# cd /usr/local/mysql/       
[root@pacteralinux mysql]# cd support-files/
[root@pacteralinux support-files]# cp my-default.cnf /etc/my.cnf   //将mysql的启动服务添加到系统服务中


(2)配置文件

vi /etc/my.cnf
basedir =/usr/local/mysql
datadir =/mnt/resource/mysqldate
port =3306
socket =/mnt/resource/mysqldate/mysql.sock
创建mysql.sock
[root@pacteralinux mysqldate]# touch mysql.sock          
[root@pacteralinux mysqldate]# ll
-rw-r--r--. 1 root root 0 Sep 25 03:26 mysql.sock




8:初始化数据库

[root@pacteralinux mysql]# ./scripts/mysql_install_db --user=mysql --no-defaults

9:设置环境变量

[root@pacteralinux mysql]# vi /root/.bash_profile
 在PATH=$PATH:$HOME/bin添加参数为:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
[root@pacteralinux mysql]# source /root/.bash_profile



10:设定启动脚本

[root@pacteralinux mysql]# cp support-files/mysql.server /etc/init.d/mysqld

11:启动数据库

  1. 启动方式一:

    [root@pacteralinux mysql]# pwd
    /usr/local/mysql
    [root@pacteralinux mysql]# ./bin/mysqld_safe --user=mysql &
    [1] 36019
    [root@pacteralinux mysql]# 130925 04:44:10 mysqld_safe Logging to '/mnt/resource/mysqldate/pacteralinux.err'.
    130925 04:44:10 mysqld_safe Starting mysqld daemon with databases from /mnt/resource/mysqldate
    130925 04:44:11 mysqld_safe mysqld from pid file /mnt/resource/mysqldate/pacteralinux.pid ended


  2. 启动方式二:

    [root@pacteralinux mysqldate]# service mysql start
    mysql: unrecognized service


 3.  启动方式三:

[root@pacteralinux mysqldate]#  /etc/rc.d/init.d/mysqld start
Starting MySQL.The server quit without updating PID file (/mnt/resource/mysqldate/pacteralinux.pid).[FAILED]

可以看到,每种启动方式都是报错

在MYSQL启动老失败即:Starting MySQL.Manager of pid-file quit without updating file.[FAILED]
查看错误日志显示:mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
/usr/local/mysql/bin/mysqld: Table 'mysql.plugin' doesn't exist

Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
InnoDB: The first specified data file ./ibdata1 did not exist:

这是执行scripts/mysql_install_db --user=mysql没有成功的原因,没有一个初始化数据库,不能启动mysql守护进程,重新执行

 
[root@pacteralinux mysql]# scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/mnt/resource/mysqldate --user=mysql

重新启动:

[root@pacteralinux mysql]# /etc/rc.d/init.d/mysqld start
Starting MySQL[  OK  ]
[root@pacteralinux mysql]# service mysql start
mysql: unrecognized service
#解决
[root@pacteralinux mysql]# chkconfig mysqld on
[root@pacteralinux mysql]# service mysql start
mysql: unrecognized service
[root@pacteralinux mysql]# service mysqld start
Starting MySQL[  OK  ]

12;连接数据库

[root@pacteralinux mysql]# mysql -u root mysql
                                  mysql>
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
Mysql刚安装完有两个数据库:mysql和test。mysql库非常重要,它里面有MySQL的系统信息,我们改密码和新增用户,实际上就是用这个库中的相关表进行操作。
mysql> use mysql
Database changed
mysql> show tables
mysql> describe user

mysql> select * from user

13:增加数据用户

格式:grant select on 数据库.* to 用户名@登录主机 identified by "密码"
例1、增加一个用户user_1密码为123,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入MySQL,然后键入以下命令:

mysql> grant select,insert,update,delete on *.* to user_1@"%" Identified by "123";


例1增加的用户是十分危险的,如果知道了user_1的密码,那么他就可以在网上的任何一台电脑上登录你的MySQL数据库并对你的数据为所欲为了,解决办法见例2。


例2、增加一个用户user_2密码为123,让此用户只可以在localhost上登录,并可以对数据库aaa进行查询、插入、修改、删除的操作(localhost指本地主机,即MySQL数据库所在的那台主机),这样用户即使用知道user_2的密码,他也无法从网上直接访问数据库,只能通过MYSQL主机来操作aaa库。


mysql>grant select,insert,update,delete on aaa.* to user_2@localhost identified by "123";

14:修改MySQL的root用户的密码以及打开远程连接

[root@ pacteraLinux]# mysql -u root mysql  mysql>use mysql;
mysql>desc user;
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";  //为root添加远程连接的能力。
mysql>update user set Password = password('xxxxxx') where User='root';
mysql>select Host,User,Password  from user where User='root';
mysql>flush privileges;
mysql>exit
#重新登录
mysql -u root -p
#若还不能进行远程连接,则关闭防火墙
[root@ pacteraLinux~]# /etc/rc.d/init.d/iptables stop

我的

mysql> use mysql;
Database changed
mysql> select host,user, password from user where user='root';
+--------------+------+----------+
| host         | user | password |
+--------------+------+----------+
| localhost    | root |          |
| pacteralinux | root |          |
| 127.0.0.1    | root |          |
| ::1          | root |          |
+--------------+------+--
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "fuwenchao";
Query OK, 0 rows affected (0.01 sec)
mysql> select host,user, password from user where user='root';
+--------------+------+-------------------------------------------+
| host         | user | password                                  |
+--------------+------+-------------------------------------------+
| localhost    | root |                                           |
| pacteralinux | root |                                           |
| 127.0.0.1    | root |                                           |
| ::1          | root |                                           |
| %            | root | *D5D3DEF34B78BED2B9ED4C0FBF3436E1E395665 |
+--------------+------+-------------------------------------------+
5 rows in set (0.00 sec)
[root@pacteralinux ~]# mysql -u root -p fuwenchao
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
mysql> update user set Password = password('mysql@pactera') where User='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 5  Changed: 4  Warnings: 0
mysql>  select host,user, password from user where user='root';
+--------------+------+-------------------------------------------+
| host         | user | password                                  |
+--------------+------+-------------------------------------------+
| localhost    | root | *D5D3DEF34B78BED2B9ED4C0FBF3436E1E395665 |
| pacteralinux | root | *D5D3DEF34B78BED2B9ED4C0FBF3436E1E395665 |
| 127.0.0.1    | root | *D5D3DEF34B78BED2B9ED4C0FBF3436E1E395665 |
| ::1          | root | *D5D3DEF34B78BED2B9ED4C0FBF3436E1E395665 |
| %            | root | *D5D3DEF34B78BED2B9ED4C0FBF3436E1E395665 |
+--------------+------+-------------------------------------------+
5 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
[root@pacteralinux mysql]# mysql -u root -p 
Enter password:
mysql>

15:错误总结

    15.1出现过如下错误,数据库启动正常,但是连接不上mysql,如下

   

[root@pacteralinux mysql]# service mysqld restart
Shutting down MySQL...[  OK  ]
Starting MySQL....[  OK  ]
[root@pacteralinux mysql]# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/mnt/resource/mysqldate/mysql.sock' (111)

 

解决方法
1,在数据存放目录下创建/mnt/resource/mysqldate/mysql.sock文件
2,在配置配件/etc/my.cnf中添加socket =/mnt/resource/mysqldate/mysql.sock

配置文件全文如下:
[root@pacteralinux mysqldate]# vi /etc/my.cnf
[client]
socket =/mnt/resource/mysqldate/mysql.sock
[mysqld]
basedir =/usr/local/mysql
datadir =/mnt/resource/mysqldate
port =3306
socket =/mnt/resource/mysqldate/mysql.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


15.2:在配置文件中添加了几个配置选项时出现过错误,
The server quit without updating PID file
增加的几条配置为全部从A服务器复制过来的,但是出现了错误,说明尽管数据库一样,对不同的版本差异很大!

15.36.4 ;本地登陆可以,但是远程登录报如下错误
连接mysql时 出现错误

ERROR 2003 (HY000): Can't connect to MySQL server on 'xx.xx.xx.xx' (110)

复制代码
此处错误id 110 用perror 查出结果为

OS error code 110:  Connection timed out

复制代码
可以查看一下网络是否正常,使用

telnet xx.xx.xx.xx 3306

发现端口不通,ping 一下该主机,也没反应!关闭防火墙之后问题依旧,打电话给云平台的admin,发现外围网络屏蔽了该端口!

mysql5.6.14 安装笔记_cnetos6.4 _03