原文地址:http://blog.csdn.net/u012453843/article/details/53048412
在Hadoop开发的时候我们要用到mysql数据库,因此我们有必要学习一下怎样在Linux下安装mysql。
第一步:下载MySQL-client-5.1.73-1.glibc23.x86_64.rpm和MySQL-server-5.1.73-1.glibc23.x86_64.rpm
我们在地址栏输入:http://ftp.ntu.edu.tw/pub/MySQL/Downloads/MySQL-5.1/回车就会看到如下图所示界面,我们找到我们要下载的文件进行下载。
第二步:将上面下载的两个文件上传到服务器,这里我用的是CentOS虚拟机,我们可以使用FileZilla工具将文件上传上去。如下图所示。
第三步:先安装MySQL-server-5.1.73-1.glibc23.x86_64.rpm
[root@itcast05 ~]# ls
anaconda-ks.cfg Desktop hadoop-2.2.0 install.log.syslog MySQL-client-5.1.73-1.glibc23.x86_64.rpm protobuf-2.5.0.tar.gz Templates
apache-ant-1.9.2-bin.tar.gz Documents hadoop-2.2.0.tar.gz jdk-7u80-linux-x64.gz MySQL-server-5.1.73-1.glibc23.x86_64.rpm Public Videos
apache-maven-3.0.5-bin.tar.gz Downloads install.log Music Pictures target
我们使用命令rpm -ivh MySQL-server-5.1.73-1.glibc23.x86_64.rpm来进行安装,其中i是安装的意思,v是显示详情的意思,h是显示进度条的意思。我们会发现与本地已经安装的mysql数据库发生了冲突。
[root@itcast05 ~]# rpm -ivh MySQL-server-5.1.73-1.glibc23.x86_64.rpm
Preparing... ########################################### [100%]
file /usr/share/mysql/charsets/README from install of MySQL-server-5.1.73-1.glibc23.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64
file /usr/share/mysql/charsets/Index.xml from install of MySQL-server-5.1.73-1.glibc23.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64
file /usr/share/mysql/charsets/armscii8.xml from install of MySQL-server-5.1.73-1.glibc23.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64
file /usr/share/mysql/charsets/ascii.xml from install of MySQL-server-5.1.73-1.glibc23.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64
省略了一部分信息
[root@itcast05 ~]#
既然发生了冲突,我们便来解决这个问题,我们先找到本地已有的mysql,我们使用命令rpm -qa | grep mysql可以找到本地的mysql。
[root@itcast05 ~]# rpm -qa | grep mysql
mysql-libs-5.1.73-7.el6.x86_64
找到mysql-libs-5.1.73-7.el6.x86_64之后我们来卸载它,使用的命令是rpm -e mysql-libs-5.1.73-7.el6.x86_64,我们会发现报错了,说有依赖项。
[root@itcast05 ~]# rpm -e mysql-libs-5.1.73-7.el6.x86_64
error: Failed dependencies:
libmysqlclient.so.16()(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_7.1.x86_64
libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_7.1.x86_64
mysql-libs is needed by (installed) postfix-2:2.6.6-6.el6_7.1.x86_64
那么我们就使用强制卸载的方式来卸载,方法是在命令后加--nodeps,意思是强制解除依赖关系。
[root@itcast05 ~]# rpm -e mysql-libs-5.1.73-7.el6.x86_64 --nodeps
[root@itcast05 ~]#
卸载完了原来的mysql,我们现在再来安装server,如下所示,发现安装成功了。
Preparing... ########################################### [100%]
1:MySQL-server ########################################### [100%]
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root -h itcast05 password 'new-password'
/usr/bin/mysql_secure_installation
databases and anonymous user created by default. This is
strongly recommended for production servers.
[root@itcast05 ~]#
Preparing... ########################################### [100%]
1:MySQL-client ########################################### [100%]
[root@itcast05 ~]#
/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.
OK, successfully used password, moving on...
root user without the proper authorisation.
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
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.
... Success!
ensures that someone cannot guess at the root password from the network.
... skipping.
access. This is also intended only for testing, and should be removed
before moving into a production environment.
... skipping.
will take effect immediately.
... Success!
installation should now be secure.
[root@itcast05 ~]#
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.73 MySQL Community Server (GPL)
affiliates. Other names may be trademarks of their respective
owners.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)