1:下载mysql
platfrom :source code
2:先安装cmake(mysql5.5以后是通过cmake来编译的)
yum安装
yum install cmake
mkdir /usr/local/mysql //安装目录mkdir /mnt/resource/mysqldate //数据存放目录
groupadd mysqluseradd -r -g mysql mysql
5:
tar -zxvf mysql.5.6.14.tar.gzcd 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
安装过程中会报很多错,大体能在一下网站解决
================================================================================================
====================================================================
下载的版本有问题。
正确的版本如下:
1、
2、选择
3、
4、
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(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.cnfbasedir =/usr/local/mysqldatadir =/mnt/resource/mysqldateport =3306socket =/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:启动数据库
启动方式一:
[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/mysqldate130925 04:44:11 mysqld_safe mysqld from pid file /mnt/resource/mysqldate/pacteralinux.pid ended
启动方式二:
[root@pacteralinux mysqldate]# service mysql startmysql: unrecognized service
3. 启动方式三:
[root@pacteralinux mysqldate]# /etc/rc.d/init.d/mysqld startStarting MySQL.The server quit without updating PID file (/mnt/resource/mysqldate/pacteralinux.pid).[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.
这是执行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 startStarting MySQL[ OK ][root@pacteralinux mysql]# service mysql startmysql: unrecognized service#解决[root@pacteralinux mysql]# chkconfig mysqld on[root@pacteralinux mysql]# service mysql startmysql: unrecognized service[root@pacteralinux mysql]# service mysqld startStarting MySQL[ OK ]
12;连接数据库
[root@pacteralinux mysql]# mysql -u root mysql mysql>mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || test |+--------------------+
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 changedmysql> 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 fuwenchaoEnter 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: 0mysql> 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 restartShutting down MySQL...[ OK ]Starting MySQL....[ OK ][root@pacteralinux mysql]# mysql -u root -pEnter password:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/mnt/resource/mysqldate/mysql.sock' (111)
[root@pacteralinux mysqldate]# vi /etc/my.cnf[client]socket =/mnt/resource/mysqldate/mysql.sock[mysqld]basedir =/usr/local/mysqldatadir =/mnt/resource/mysqldateport =3306socket =/mnt/resource/mysqldate/mysql.socksql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
ERROR 2003 (HY000): Can't connect to MySQL server on 'xx.xx.xx.xx' (110)
OS error code 110: Connection timed out
telnet xx.xx.xx.xx 3306