通过rpm包安装、配置及卸载mysql

 

通过rpm包安装、配置及卸载mysql的详细过程.

以MySQL-server-4.0.14-0.i386.rpm为例,放在/data目录下

cd /data

rpm -ivh MySQL-server-4.0.14-0.i386.rpm

安装完成后在/usr/share/mysql目录中会有一个mysql的启动脚本mysql.server及示例配置文件等(如my-huge.cnf、my-large.cnf、my-medium.cnf)

拷贝一个示例配置文件作为mysql的配置文件:

cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

rpm包安装完后自动将mysql安装成系统服务,所以可以使用下面命令启动、停止mysql

启动mysql

/etc/init.d/mysql start 或 service mysql start

停止mysql

/etc/init.d/mysql stop 或 service mysql stop

到此,mysql服务就安装配置完成。

安装mysql客户端

rpm -ivh MySQL-client-4.0.14-0.i386.rpm

mysql安装好后目录结构如下:

工具程序在/usr/bin目录中---ls /usr/bin/mysql*

服务器程序/usr/sbin/mysqld

数据目录/var/lib/mysql

默认情况下mysql将错误日志文件、二进制日志文件及进程文件写在/var/lib/mysql目录中,如localhost.err、localhost.pid、localhost-bin.001等

要改变这些情况可以修改/etc/my.cnf文件

如将日志文件写在/var/log目录中,可以在my.cnf文件中加入下面两行:

[mysqld_safe]

err-log = /var/log/mysqld.log

有个实用程序/usr/bin/mysql_install_db,该程序可以用来初始化mysql数据库,即创建/var/log/mysql目录,及创建mysql数据库(mysql授权表等信息)及test数据库(空库),如果不小心删除了/var/log/mysql目录可以通过该程序来初始化.

卸载mysql

rpm -qa|grep -i mysql

rpm -ev MySQL-server-4.0.14-0 MySQL-client-4.0.14-0

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

rm -f /etc/my.cnf

rm -rf /var/lib/mysql

安装过程信息如下:

安装顺序
     rpm -ivh mysql-3.23.41-1.i386.rpm
  rpm -ivh mysql-devel-3.23.41-1.i386.rpm
  rpm -ivh mysql-server-3.23.41-1.i386.rpm


[root@localhost perl]# rpm -ivh mysql-3.2*.rpm   //第一个包就不顺
warning: mysql-3.23.52-3.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
error: Failed dependencies:
         perl-DBI is needed by mysql-3.23.52-3
         perl-DBD-MySQL is needed by mysql-3.23.52-3
         perl(CGI) is needed by mysql-3.23.52-3
         perl(DBI) is needed by mysql-3.23.52-3

down perl-DBD-MySQL在disk3/redhat/RPMS下
      perl-DBI在disk2/redhat/RPMS下
     


[root@localhost perl]# rpm -ivh perl-CGI*.rpm    //以后会用到先装
warning: perl-CGI-2.81-55.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
Preparing...                 ########################################### [100%]
    1:perl-CGI                ########################################### [100%]

[root@localhost perl]# rpm -ivh perl-DBI*
warning: perl-DBI-1.30-1.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
Preparing...                 ########################################### [100%]
    1:perl-DBI                ########################################### [100%]

[root@localhost perl]# rpm -ivh perl-DBD-MySQL*
warning: perl-DBD-MySQL-2.1017-3.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
error: Failed dependencies:
         libmysqlclient.so.10 is needed by perl-DBD-MySQL-2.1017-3

google "libmysqlclient.so.10 mysql"    //呵呵这个可是难倒了很多好汉


[root@localhost perl]# rpm -ivh libmysql*
warning: libmysql10-3.23.56-1.4mdk.i586.rpm: V3 DSA signature: NOKEY, key ID 22458a98
Preparing...                 ########################################### [100%]
    1:libmysql10              ########################################### [100%]

[root@localhost perl]# rpm -ivh perl-DBD-MySQL*
warning: perl-DBD-MySQL-2.1017-3.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
Preparing...                 ########################################### [100%]
    1:perl-DBD-MySQL          ########################################### [100%]



[root@localhost perl]# rpm -ivh mysql-3.23*
warning: mysql-3.23.52-3.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
Preparing...                 ########################################### [100%]
    1:mysql                   ########################################### [100%]
[root@localhost perl]# rpm -ivh mysql-devel*
warning: mysql-devel-3.23.52-3.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
Preparing...                 ########################################### [100%]
    1:mysql-devel             ########################################### [100%]
[root@localhost perl]# rpm -ivh mysql-server*
warning: mysql-server-3.23.52-3.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
Preparing...                 ########################################### [100%]
    1:mysql-server            ########################################### [100%]

安装测试
     [root@localhost perl]# mysql
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
     在搜索里找不到mysql执行程序,只有rpm安装包
     在“服务”-看到了新增的 mysqld 打勾,restart
     [root@localhost perl]# mysql
Welcome to the MySQL monitor.   Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 3.23.52

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>;

mysql成功安装并启动


因为缺省情况下mysql的root用户没有口令,使用下列
[root@localhost perl]# mysqladmin -u root password 747858969
[root@localhost perl]# mysql
ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)

[root@localhost etc]# mysql -u root -p
Enter password:****
mysql>;

你可能感兴趣的:(mysql)