Linux下利用rpm包安装mysql

迈不过友情╰ 2022-06-12 04:43 278阅读 0赞

最近由于项目关系弄了下mysql cluster和mysql,中心数据库用的是mysql cluster,前置机数据库用的是mysql,这是先写下mysql的安装作为以后查看用。

1.软件包准备:在 http://www.mysql.com/downloads/mysql-4.0.html 上下载 MySQL-server-5.5.23-1.linux2.6.i386.rpm 和 MySQL-client-5.5.23-1.linux2.6.i386.rpm

2.安装mysql

1)安装服务器端

在rpm包的目录下运行以下命令:

[root@gc01vm4 local]# rpm -ivh MySQL-server-5.5.23-1.linux2.6.i386.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 gc01vm4 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! ”

如出现如上信息,则表示服务器端安装成功

  1. 2)安装客户端

运行如下命令

[root@gc01vm4 local]# rpm -ivh MySQL-client-5.5.23-1.linux2.6.i386.rpm

显示如下信息则表明安装成功:

Preparing… ########################################### [100%]
1:MySQL-client ########################################### [100%]

3.启用mysql服务

运行如下命令:

[root@gc01vm4 init.d]# /etc/init.d/mysql start 或者用mysqld_safe & 命令来启动数据库

mysql 的默认端口是3306,这时可以 用netstat来查看mysql端口是否打开

[root@gc01vm4 init.d]# netstat -nat

如果显示中有tcp 0 0 :::3306 :::* LISTEN 这条则表示服务已启动。

用ps -e 命令可以查看到进程中有mysqld进程

附:rpm包的卸载:# rpm -qa | grep MySQL
MySQL-server-5.0.27-0.glibc23
然后,
# rpm -e —nodeps MySQL-server-5.0.27-0.glibc23

  1. 不行的话可以用\#rpm -e --allmatches MySQL-server-5.0.27-0.glibc23 搞定。再
  2. \# find / -name mysql
  3. /var/lib/mysql
  4. /var/lib/mysql/mysql
  5. /var/lock/subsys/mysql
  6. mysql的相关文件应该可以手动删除了 示例 rm -rf /var/lib/mysql
  7. mysql停止:/usr/bin/mysqladmin -u root -p shutdown
  8. rpm命令参数:--force忽略软件包及文件的冲动
  9. --nodeps 不检查依赖性关系
  10. --dbpath设置RPM资料库所在的路径
  11. --prefix 将软件包安装到由指定的目录下

4.登录mysql

第一次登录只需键入mysql

[root@gc01vm4 init.d]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.23 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>

出现如上提示刚表示登录成功

修改密码:[root@gc01vm4 init.d]# /usr/bin/mysqladmin -u root password ‘111111’

这时将密码改为了六个1,离开mysql键入exit即可,再次登录刚需要输入

[root@gc01vm4 init.d]# mysql -u root -p
Enter password:

输入密码回车即可。

5.mysql的几个重要目录

  1. 数据库目录

  /var/lib/mysql/

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

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

  1. 启动脚本

  /etc/rc.d/init.d/(启动脚本文件mysql的目录)

6.建库、建表、插入记录等基本操作

1)建库 mysql> create databases orcl;

2) 打开库 mysql> use orcl; (打开库,对每个库进行操作就要打开此库,类似于foxpro )
   Database changed

3) 建表

mysql> create table name (id int(3) auto_increment not null primary key, xm char(8),xb char(2),csny date);

4)查看表结构

mysql> describe name;

  +———-+————-+———+——-+————-+————————+
  | Field | Type  | Null | Key | Default | Extra     |
  +———-+————-+———+——-+————-+————————+
  | id  | int(3) |   | PRI | NULL  | auto_increment |
  | xm  | char(8) | YES |   | NULL  |        |
  | xb  | char(2) | YES |   | NULL  |        |
  | csny | date  | YES |   | NULL  |        |
  +———-+————-+———+——-+————-+————————+

5)插入表记录

mysql> insert into name values(‘’,’张三’,’男’,’1971-10-01’);
  mysql> insert into name values(‘’,’白云’,’女’,’1972-05-20’);
  可用select命令来验证结果。
  mysql> select * from name;
  +——+———+———+——————+
  | id | xm  | xb  | csny    |
  +——+———+———+——————+
  | 1 | 张三 | 男  | 1971-10-01 |
  | 2 | 白云 | 女  | 1972-05-20 |
  +——+———+———+——————+

到这里后面操作跟oracle操作类似了……

发表评论

表情:
评论列表 (有 0 条评论,278人围观)

还没有评论,来说两句吧...

相关阅读

    相关 rpm安装mysql

    如何用源码包安装MySQL数据库 下载源码,里面安装说明,一般都是./configure。。。。。。makeinstall,安装起来很慢 本回答由提问者推荐 如何用

    相关 Linux-RPM安装

    yum是Red Hat所特有的安装RPM程序包的工具。使用RPM工具安装某一个程序包时,有可能会因为该程序包依赖另一个程序包而无法安装;而使用yum工具时,就可以连同依赖的程序