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-*不行
用下列方式就成功了~
# rpm -e MySQL-server-community-5.0.82-0.rhel5
#rpm -e MySQL-client-community-5.0.82-0.rhel5


  卸载后/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&amp;characterEncoding=UTF-8"
              username="root" password="" maxActive="20" maxIdle="10"
              maxWait="-1"/>即可。

注意url部分,在xml文件中&需写成&amp;
而在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.安装过程中出现的错误及解决方法
Starting MySQL.Manager of pid-file quit without updating fi[FAILED]
上网查了很多方法 一种是打开 /etc/selinux/config把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器后问题就得以解决。
貌似解决了,上次去部署工程的时候在名字节点上就是这样改的。

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


[root@HPDS-1 myang]# 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



============================================================================================
强制安装
那试试
rpm -ivh *.rpm --force --nodeps


/////////替换
rpm -ivh --replacefiles **.rpm


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

还没验证过上面的方法。

你可能感兴趣的:(mysql,linux,Hibernate,jdbc,redhat)