Linux_RedHat下安装MySQL出现的问题及解决方法

安装过程中出现的问题及解决方法;
1.卸载mysql
之前装过一次,不过不是rpm的,安装很麻烦,而且没成功。昨天又装了一次rpm的,安装很容易,不过修改root用户的host时候出现了问题,重新登陆后发现看不见mysql数据库了,奇怪~只有选择卸载……

卸载mysql
  rpm -qa|grep -i mysql显示安装的包名
会显示
MySQL-server-community-5.0.82-0.rhel5
MySQL-client-community-5.0.82-0.rhel5

  rpm -ev MySQL-server-5.0.8-0 MySQL-client-5.0.8-0(网上介绍的,不过不成功)

发现rpm -e MySQL-*不行
用下列方式就成功了~
[color=darkred]# rpm -e MySQL-server-community-5.0.82-0.rhel5
#rpm -e MySQL-client-community-5.0.82-0.rhel5[/color]

  卸载后/var/lib/mysql中的数据及/etc/my.cnf不会删除,如果确定没用
后就手工删除

  rm -f /etc/my.cnf

rm -rf /var/lib/mysql

介绍一下mysql安装完后的几个目录
   1)数据库目录
   /var/lib/mysql/

   2)配置文件
   /usr/share/mysql(mysql.server命令及配置文件)

   3)相关命令
   /usr/bin(mysqladmin mysqldump等命令)

   4)启动脚本
   /etc/rc.d/init.d/(启动脚本文件mysql的目录)
我从这些目录中把带mysql的文件都删除了
用sudo rm –f mysql;

2. 数据库连接配置
数据库连接采用了hibernate和JDBC两种方式
Hibernate的话更改配置很方便,但是JDBC如果用class.forName的方式则不利用程序的移植,数据库地址改了的话还得重新编译,所以采用了JNDI
在tomcat的context.xml中加入

<Resource name="jdbc/pcms" auth="Container"
type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://10.2.1.10:3306/pcms?useUnicode=true&characterEncoding=UTF-8"
username="root" password="" maxActive="20" maxIdle="10"
maxWait="-1"/>即可。

注意url部分,在xml文件中&需写成&
而在java程序中只需用&

程序中写成:
public static Connection getConnection()
{
Connection cs=null;
try{
Context ctx = new InitialContext();
//JNDI ok
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/pcms");
cs = ds.getConnection();
}catch(SQLException se)
{
se.getMessage();
} catch (NamingException e) {
e.printStackTrace();
}
return cs;
}

3.MySQL启动问题
MySQL安装完后就是随系统自动启动了的,如果没有的话需要做一点设置:
让mysql自动启动
# cp /usr/local/share/mysql/mysql.server /etc/init.d/mysqld
#chkconfig mysqld on

4.安装过程中出现的错误及解决方法
[color=red]Starting MySQL.Manager of pid-file quit without updating fi[FAILED][/color]
上网查了很多方法 一种是打开[color=darkred]/etc/selinux/config把SELINUX=enforcing改为SELINUX=disabled[/color]后存盘退出重启机器后问题就得以解决。
貌似解决了,上次去部署工程的时候在名字节点上就是这样改的。

[color=red]ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)[/color]这是没启动mysql的守护进程,执行[color=darkred]service mysqld start[/color]就行了!


[color=red]# rpm -ivh MySQL-server-5i386.rpm
error: Failed dependencies:
/bin/sh is needed by MySQL-server-community-5.0.82-0.rhel5.i386
/usr/bin/perl is needed by MySQL-server-community-5.0.82-0.rhel5.i386
chkconfig is needed by MySQL-server-community-5.0.82-0.rhel5.i386
coreutils is needed by MySQL-server-community-5.0.82-0.rhel5.i386
grep is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libc.so.6 is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libc.so.6(GLIBC_2.0) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libc.so.6(GLIBC_2.1) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libc.so.6(GLIBC_2.1.2) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libc.so.6(GLIBC_2.1.3) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libc.so.6(GLIBC_2.2) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libc.so.6(GLIBC_2.3) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libc.so.6(GLIBC_2.3.4) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libc.so.6(GLIBC_2.4) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libcrypt.so.1 is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libcrypt.so.1(GLIBC_2.0) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libdl.so.2 is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libdl.so.2(GLIBC_2.0) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libdl.so.2(GLIBC_2.1) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libm.so.6 is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libm.so.6(GLIBC_2.0) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libm.so.6(GLIBC_2.1) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libnsl.so.1 is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libpthread.so.0 is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libpthread.so.0(GLIBC_2.0) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libpthread.so.0(GLIBC_2.1) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libpthread.so.0(GLIBC_2.2) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
libpthread.so.0(GLIBC_2.3.2) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
librt.so.1 is needed by MySQL-server-community-5.0.82-0.rhel5.i386
procps is needed by MySQL-server-community-5.0.82-0.rhel5.i386
rtld(GNU_HASH) is needed by MySQL-server-community-5.0.82-0.rhel5.i386
shadow-utils is needed by MySQL-server-community-5.0.82-0.rhel5.i386[/color]


============================================================================================
[color=darkred]强制安装
那试试
rpm -ivh *.rpm --force --nodeps


/替换
rpm -ivh --replacefiles **.rpm[/color]

这个问题上次出现了,今天去却没出现 怪异了 不知道是不是和设置了selinux=disabled有关

还没验证过上面的方法。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值