mysql安装for linux(rpm包)


一.安装Mysql
1.Mysql的安装包有很多个,作用也不同,在大多数情况下,只需要安装 MySQL-server 和  MySQL-client , 其他的包根据需要来安装。
   --在Mysql安装时,会创建mysql用户和mysql组。

2.mysql的相关目录说明
/usr/bin :   client programs and scripts   --mysqladmin mysqldump等命令
/ust/sbin :  the mysqld server
/var/lib/mysql : log files,databases   --这个目录就是数据库的目录
/usr/share/info : Manual in Info format
/usr/share/man : unix manual pages
/usr/include/mysql : include(header) files
/usr/lib/mysql : libraries
/usr/share/mysql : miscellaneous support files,including error messages, character set files, sample configuration files,sql for database installation  
 --mysql.server  命令及配置文件
/usr/share/sql-bench: Benchmarks
/ect/rc.d/init.d/: 启动脚本文件mysql的目录

  3.安装server端:

[root@zw oradata]# tar -xvf MySQL-5.5.18-1.linux2.6.x86_64.tar
[root@zw oradata]#ll
-rw-r--r-- 1   7161 wheel  17730789 Nov 14  2011 MySQL-5.5.18-1.linux2.6.x86_64.tar
-rw-r--r-- 1   7161 wheel  17730789 Nov 14  2011 MySQL-client-5.5.18-1.linux2.6.x86_64.rpm
-rw-r--r-- 1   7161 wheel   6478729 Nov 14  2011 MySQL-devel-5.5.18-1.linux2.6.x86_64.rpm
-rw-r--r-- 1   7161 wheel  66914339 Nov 14  2011 MySQL-embedded-5.5.18-1.linux2.6.x86_64.rpm
-rw-r--r-- 1   7161 wheel  52986206 Nov 14  2011 MySQL-server-5.5.18-1.linux2.6.x86_64.rpm
-rw-r--r-- 1   7161 wheel   2003852 Nov 14  2011 MySQL-shared-5.5.18-1.linux2.6.x86_64.rpm
-rw-r--r-- 1   7161 wheel  41200449 Nov 14  2011 MySQL-test-5.5.18-1.linux2.6.x86_64.rpm


[root@zw oradata]# rpm  -ivh  MySQL-server-5.5.18-1.linux2.6.x86_64.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 zw 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!


--安装客户端
[root@zw oradata]# rpm -ivh MySQL-client-5.5.18-1.linux2.6.x86_64.rpm
Preparing...                   ########################################### [100%]
   1:MySQL-client           ########################################### [100%]


2.3 其他操作
  2.3.1查看在时创建的mysql用户和mysql group:
[root@zw oradata]# cat /etc/passwd |grep mysql
mysql:x:101:104:MySQL server:/var/lib/mysql:/bin/bash

[root@zw oradata]# cat /etc/group |grep mysql
mysql:x:104:



2.3.2修改密码
--连接mysql报错:
[root@zw oradata]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

--启动mysql后,在连正常
[root@zw oradata]# /etc/init.d/mysql start
Starting MySQL..                                           [  OK  ]

[root@zw oradata]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.18 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>
 --注意这里,因为mysql默认没有密码,所以在这里我们没有输入密码就直接连上了。

--修改密码,这个是安装server中提示的:
[root@zw oradata]# /usr/bin/mysqladmin -u root password root

[root@zw oradata]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
--修改密码后,就提示要使用密码了。

[root@zw oradata]#  mysql -u root -p
Enter password:          
--输入密码后连接成功
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.18 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> 

2.3.3 查看MySQL 端口 3306 , 这个是默认的端口:

[root@zw oradata]# netstat -nat|grep 3306
tcp        0      0 :::3306                     :::*                        LISTEN    

 
2.3.4 设置开机启动
--查看mysql开机启动设置:
[root@zw oradata]# chkconfig --list |grep mysql
mysql               0:off     1:off      2:on     3:on     4:on     5:on     6:off
这里的数字分别代表linux启动的不同模式,3是命令行,5是窗口。

--关闭开机自启动
[root@zw oradata]# chkconfig mysql off
[root@zw oradata]# chkconfig --list |grep mysql
mysql               0:off     1:off      2:off     3:off     4:off     5:off     6:off

--使用开机启动
[root@zw oradata]# chkconfig mysql on
[root@zw oradata]# chkconfig --list |grep mysql
mysql               0:off     1:off     2:on     3:on     4:on     5:on     6:off

--将mysql从chkconfig服务里删除:
[root@zw oradata]# chkconfig --del mysql
[root@zw oradata]# chkconfig --list |grep mysql
[root@zw oradata]#

 -- 将mysql添加到chkconfig服务里:
[root@zw oradata]# chkconfig --add mysql
[root@zw oradata]# chkconfig --list |grep mysql
mysql               0:off     1:off     2:on     3:on     4:on     5:on     6:off

2.4数据库操作
[root@zw oradata]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.18 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>
 
--查看已经存在的数据库,这几个是安装时自动创建的
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)


--使用mysql 数据库
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed


--查看 mysql 数据库下面的表

mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
24 rows in set (0.00 sec)

--创建数据库zw
mysql> create database zw;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
zw                 |
+--------------------+
5 rows in set (0.00 sec)

--在zw数据库下面创建zw表
user zw;
create table zw(id int,name char(20));

--查看zw表结构
mysql> desc zw;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id    | int(11)  | YES  |     | NULL    |       |
| name  | char(20) | YES  |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.01 sec)

--查看zw数据库下的表
mysql> show tables;
+--------------+
| Tables_in_zw |
+--------------+
| zw                |
+--------------+
1 row in set (0.00 sec)

--向zw表里插入2条表记录
mysql> insert into zw values(1,'zw');
Query OK, 1 row affected (0.01 sec)

mysql> insert into zw values(2,'zt');
Query OK, 1 row affected (0.00 sec)

--查看表里的数据
mysql> select * from zw;
+------+------+
| id   | name |
+------+------+
|    1 | zw   |
|    2 | zt   |
+------+------+
2 rows in set (0.00 sec)

--update 表
mysql> update zw set name='zwzw' where id=1;
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0


select * from zw;
mysql> select * from zw;
+------+------+
| id   | name |
+------+------+
|    1 | zwzw |
|    2 | zt       |
+------+------+
2 rows in set (0.00 sec)

--drop 表
mysql> drop table zw;
Query OK, 0 rows affected (0.00 sec)

--drop 数据库
mysql> drop database zw;
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值