linux 安装mysql

最近由于项目关系弄了下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!  ”

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

    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

                                 不行的话可以用#rpm -e --allmatches  MySQL-server-5.0.27-0.glibc23  搞定。再
                                 # find / -name mysql
                                 /var/lib/mysql
                                 /var/lib/mysql/mysql
                                 /var/lock/subsys/mysql
                                mysql的相关文件应该可以手动删除了 示例 rm -rf /var/lib/mysql 

           mysql停止:/usr/bin/mysqladmin -u root -p shutdown

           rpm命令参数:--force忽略软件包及文件的冲动

                                   --nodeps 不检查依赖性关系

                                   --dbpath设置RPM资料库所在的路径

                                   --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的几个重要目录

       数据库目录
  /var/lib/mysql/

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

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

       启动脚本
  /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 |
  +----+------+------+------------+

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值