`
wuhuizhong
  • 浏览: 682547 次
  • 性别: Icon_minigender_1
  • 来自: 中山
社区版块
存档分类
最新评论

安裝MySQL-server-5.5.30 for Redhat linux 5.10

 
阅读更多

系统环境
--------

sudo yum -y install gcc gcc-c++ make automake autoconf ncurses-devel libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel pcre-devel libtool-libs freetype-devel gd zlib-devel file bison patch mlocate flex diffutils readline-devel glibc-devel glib2-devel bzip2-devel gettext-devel libcap-devel libmcrypt-devel
sudo yum -y install libaio
sudo yum -y install libaio-devel

检查是否安装过MySQL
-------------------

# rpm -qa | grep mysql
mysql-libs-5.1.71-1.el6.x86_64

卸载老版本的MySQL
-----------------

因为是依赖包的原因,所以需要强制删除,在后边多加一个参数

$ sudo rpm -e mysql-libs --nodeps


下载MySQL安装包rpm文件
----------------------

进入MySQL官方网站找到对应版本,一般需要下载3个文件
MySQL-server
MySQL-client
MySQL-devel

官网地址
http://dev.mysql.com/downloads/mysql/#downloads
   
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-server-5.5.30-1.el6.x86_64.rpm/from/http://mysql.spd.co.il/
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-client-5.5.30-1.el6.x86_64.rpm/from/http://mysql.spd.co.il/
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-devel-5.5.30-1.el6.x86_64.rpm/from/http://mysql.spd.co.il/

在当前下载好的目录用 rpm -ivh 安装
   
[vagrant@localhost vagrant]$ sudo rpm -ivh MySQL-server-5.5.30-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

Please report any problems with the /usr/bin/mysqlbug script!

[vagrant@localhost vagrant]$ sudo rpm -ivh MySQL-client-5.5.30-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]
[vagrant@localhost vagrant]$ sudo rpm -ivh MySQL-devel-5.5.30-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:MySQL-devel            ########################################### [100%]

[vagrant@localhost vagrant]$ mysql --version
mysql  Ver 14.14 Distrib 5.5.30, for Linux (x86_64) using readline 5.1

[vagrant@localhost vagrant]$ sudo service mysql start
Starting MySQL.. SUCCESS!


安装路径是/usr/share/mysql
数据存放路径/var/lib/mysql/
my.cnf配置文件
sudo mysql --help | grep my.cnf
[vagrant@localhost mysql]$  ps -ef |grep mysql
root      2936     1  0 13:58 pts/0    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pid
mysql     3027  2936  0 13:58 pts/0    00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/localhost.localdomain.err --pid-file=/var/lib/mysql/localhost.localdomain.pid
MySQL在启动时自动使用/usr/share/mysql/my-medium.cnf文件。
复制/usr/share/mysql/my-medium.cnf文件到/etc目录,并改名为my.cnf:
$ sudo cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

迁移mysql默认数据库目录
-----------------------

建议独立设置一个默认盘,数据库IO瓶颈
1)、先将数据库停止: sudo service mysql stop
2)、先迁移数据库文件 mv /var/lib/mysql /vagrant/mysqldata/ (对应的文件夹路径)
3)、修改my.cnf (在/etc下,如果没有的去/usr/share/mysql/ 复制一个至/etc即可)
4)、修改 socket = /vagrant/mysqldata/mysql/mysql.sock
5)、修改(添加) datadir = /vagrant/mysqldata/mysql/
6)、建议增加 character-set-server = utf8
7)、建议增加 default-storage-engine = INNODB (设置默认引擎为INNODB,如果不是请忽略)
8)、启动mysql: sudo service mysqld start
[vagrant@localhost mysql]$ sudo service mysql restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL... ERROR! The server quit without updating PID file (/vagrant/mysqldata/mysql//localhost.localdomain.pid).
还原:
mv /vagrant/mysqldata/mysql /var/lib/
rm /etc/my.cnf
   
添加一个mysql管理员账号
-----------------------
   
GRANT ALL PRIVILEGES ON *.* TO [username]@'[%]' IDENTIFIED BY "[password]";
flush privileges;
([username]:账号,[%]登录ip, [password]:登录密码,可以设置固定IP登录)
(使添加的管理员即时生效)
GRANT ALL PRIVILEGES ON *.* TO whz@'%' IDENTIFIED BY "practice";
flush privileges;

在其它任何的主机上以root身份登录
--------------------------------

1、d:\mysql\bin\>mysql -h localhost -u root //这样应该可以进入MySQL服务器
2、mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; //赋予任何主机访问数据的权限
3、mysql>FLUSH PRIVILEGES; //修改生效
4、mysql>EXIT; //退出MySQL服务器
5、修改root密碼
mysql -u root -p
mysql> use mysql;
mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
mysql> FLUSH PRIVILEGES;

检查防火墙
----------

如果端口未开是不能上网的

1)、编辑防火墙规则   
vi /etc/sysconfig/iptables

2)、添加规则   
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT

3)、重启防火墙   
service iptables restart

4、检查规则是否生效   
iptables -L

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics