64位linux(Redhat5)装配Mysql5.5.14过程记录

64位linux(Redhat5)安装Mysql5.5.14过程记录

通过配置将Redhat使用CentOS的yum库。

从拖管方那拿到服务器后发现里面已经存在了数据库,

但是通过rpm -qa | grep mysql却无法找到已经安装的数据库

通过find / -name mysql 发现如下结果:

[root@HOHO ~]# find / -name mysql
/usr/local/mysql
/usr/local/mysql/include/mysql
/usr/local/mysql/lib/mysql
/usr/local/mysql/var/mysql
/usr/local/mysql/share/mysql
/usr/local/mysql/bin/mysql
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/DBD/mysql
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/mysql
/usr/lib64/mysql
/var/lib/mysql
/var/lib/mysql/mysql

运行/usr/local/mysql/bin/mysql --version发现客户端是5.0老版本的,于是想到删除老的mysql

 由于没有rpm包,所以无法通过rpm -e --nodeps mysql来删除mysql包

只好通过如下方式删除:

[root@HOHO ~]# rm -rf /usr/local/mysql/
[root@HOHO ~]# find / -name mysql
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/DBD/mysql
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/mysql
/usr/lib64/mysql
/var/lib/mysql
/var/lib/mysql/mysql
[root@HOHO ~]# ll /usr/lib64/mysql/
总计 4
drwxr-xr-x 3 root root 4096 07-20 10:55 plugin
[root@HOHO ~]# rm -rf /var/lib/mysql/
[root@HOHO ~]# find / -name mysql
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/DBD/mysql
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/mysql
/usr/lib64/mysql

 删除成功后,打算用yum install mysql安装,装完后发现版本还不是最新的5.5.14,

所以又通过yum remove mysql删除。

从mysql.com官网下载以下三个文件:

(1)MySQL-server-5.5.14-1.rhel5.x86_64

(2)MySQL-shared-5.5.14-1.rhel5.x86_64

(3)MySQL-client-5.5.14-1.rhel5.x86_64

按照以上顺序,安装如下:

[root@HOHO ~]# rpm -Uvh MySQL-server-5.5.14-1.rhel5.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 uhz000153.hichina.com 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!

[root@HOHO ~]# find / -name mysql
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/DBD/mysql
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/mysql
/usr/lib64/mysql
/usr/share/mysql
/etc/logrotate.d/mysql
/etc/rc.d/init.d/mysql
/var/lib/mysql
/var/lib/mysql/mysql
[root@HOHO ~]# find / -name mysqladmin
[root@HOHO ~]# rpm -Uvh MySQL-shared-5.5.14-1.rhel5.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-shared           ########################################### [100%]
[root@HOHO ~]# find / -name mysqladmin
[root@HOHO ~]# find / -name mysql
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/DBD/mysql
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/mysql
/usr/lib64/mysql
/usr/share/mysql
/etc/logrotate.d/mysql
/etc/rc.d/init.d/mysql
/var/lib/mysql
/var/lib/mysql/mysql
[root@HOHO ~]# rpm -Uvh MySQL-client-5.5.14-1.rhel5.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]
[root@HOHO ~]# find / -name mysql
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/DBD/mysql
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/mysql
/usr/lib64/mysql
/usr/share/mysql
/usr/bin/mysql
/etc/logrotate.d/mysql
/etc/rc.d/init.d/mysql
/var/lib/mysql
/var/lib/mysql/mysql
[root@HOHO ~]# 

 注意:如果安装过程中出错,有可能是原来的没有删干净造成的,再find下,再rm下就好。

 

安装成功后,注意这段提示:

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.

 如果是产品运行环境,可以通过/usr/bin/mysql_secure_installation进行配置。

其过程大致如下:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
mysql: Unknown OS character set 'GB18030'.
mysql: Switching to the default character set 'latin1'.
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
mysql: Unknown OS character set 'GB18030'.
mysql: Switching to the default character set 'latin1'.
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
mysql: Unknown OS character set 'GB18030'.
mysql: Switching to the default character set 'latin1'.
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
mysql: Unknown OS character set 'GB18030'.
mysql: Switching to the default character set 'latin1'.
 ... Success!
 - Removing privileges on test database...
mysql: Unknown OS character set 'GB18030'.
mysql: Switching to the default character set 'latin1'.
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
mysql: Unknown OS character set 'GB18030'.
mysql: Switching to the default character set 'latin1'.
 ... Success!

Cleaning up...



All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

 

在linux SHELL中输入mysql会有类似mysql无法识别OS Characterset GB18030,

mysql: Unknown OS character set 'GB18030'.   
mysql: Switching to the default character set 'latin1'.   

 

采用默认的latin1之类的信息,表明操作系统的编码设置需要修改,描述如下:
查看操作系统的字符集

#locale
LANG=utf8
LC_CTYPE="utf8"
LC_NUMERIC="utf8"
LC_TIME="utf8"
LC_COLLATE="utf8"
LC_MONETARY="utf8"
LC_MESSAGES="utf8"
LC_PAPER="utf8"
LC_NAME="utf8"
LC_ADDRESS="utf8"
LC_TELEPHONE="utf8"
LC_MEASUREMENT="utf8"
LC_IDENTIFICATION="utf8"
LC_ALL=

 

如果不是这样,则需要对操作系统字符集进行修改:

#vim /etc/syconfig/i18n

 

修改成:LANG="zh_CN.UTF-8"即可
另外,再查看一下环境变量的设置

#vim /etc/profile

 

里面可以没有字符集的设置,如果有,应类似如下设置:

写道
export LC_ALL="C"
#export LANG="zh_CN.UTF-8"

 

设置完成后,

#source /etc/profile

 

使环境变量生效,如果不放心,可以reboot

 

如果要通过命令创建UTF-8格式的数据库,需通过如下方式:

CREATE DATABASE `test2` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

 

(如果是GBK,则用create database test2 DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;)

增加用户

shell> mysql --user=root mysql
mysql> GRANT ALL PRIVILEGES ON *(or DBName).* TO monty@localhost
IDENTIFIED BY 'something' WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON *(or DBName).* TO monty@"%"
IDENTIFIED BY 'something' WITH GRANT OPTION;
mysql> GRANT RELOAD,PROCESS ON *(or DBName).* TO admin@localhost;
mysql> GRANT USAGE ON *.* TO dummy@localhost;