//----------------------------------------------------
//AUTHOR: lanyang123456
//DATE: 2012-4-19
//----------------------------------------------------
MySQL 版本5.0.18
系统Fedora 16 内核3.1.0
1. MySQL安装文件下载
2.具体安装.
3.登录MySQL.
4. 数据库的操作
1. MySQL安装文件下载
下载地址
http://downloads.mysql.com/archives.php?p=mysql-5.0&v=5.0.18
页面中的如下这一项
Linux (Standard, x86) (28 Dec 2005, 24.6M)
SignatureMD5:e3e5fc86e94a1d048fef70e48712f212
得到文件mysql-standard-5.0.18-linux-i686.tar.gz
安装过程参考安装文件目录下的INSTALL-BINARY文件。
2. 具体安装
解压安装文件
# tar -zxvf mysql-standard-5.0.18-linux-i686.tar.gz
生成目录mysql-standard-5.0.18-linux-i686
进入该目录
# cd mysql-standard-5.0.18-linux-i686
创建组mysql,在该组内创建用户mysql
# groupadd mysql
# useradd -g mysql mysql
解压的文件放在home目录下
做一个链接,使/usr/local/mysql链接到MySQL源文件目录
#ln –s /home/ mysql-standard-5.0.18-linux-i686 /usr/local/mysql
由于下载的是二进制文件,直接使用即可,不需要configure,make ,make install 等步骤。
进入到/usr/local/mysql目录
安装系统数据库的表
# scripts/mysql_install_db --user=mysql
Installing all prepared tables
Fill help tables
设置目录权限
# chown -R root .
# chown -R mysql var
# chgrp -R mysql .
启动MySQL Server
# bin/mysqld_safe --user=mysql &
[1] 2604
[root@localhost mysql]# nohup:忽略输入重定向错误到标准输出端
Starting mysqld daemon with databases from /var/lib/mysql
也可使用如下方式开启服务
[root@localhost mysql]# support-files/mysql.server start
Starting MySQL SUCCESS!
查看进程表,MySQL相关进程被启动
[root@localhost mysql]# ps -ef
root 2420 1 0 17:05 pts/1 00:00:00 /bin/sh ./bin/mysqld_safe --data
mysql 2455 2420 0 17:05 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --ba
mysql 2456 2455 0 17:05 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --ba
mysql 2457 2456 0 17:05 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --ba
mysql 2458 2456 0 17:05 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --ba
mysql 2459 2456 0 17:05 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --ba
mysql 2460 2456 0 17:05 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --ba
mysql 2462 2456 0 17:05 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --ba
mysql 2463 2456 0 17:05 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --ba
mysql 2464 2456 0 17:05 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --ba
mysql 2465 2456 0 17:05 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --ba
root 2546 2 0 17:06 ? 00:00:00 [kworker/0:1]
若不启动MySQL Server服务,登录时会出现
[root@localhost mysql]# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
关闭服务
[root@localhost mysql]# mysqladmin -u root -p shutdown
Enter password:
STOPPING server from pid file /var/run/mysqld/mysqld.pid
120416 20:50:25 mysqld ended
[1]+ 完成 bin/mysqld_safe
[root@localhost mysql]#
3.登录MySQL
登录MySQL的命令是mysql, mysql的使用语法如下:
mysql [-u username] [-h host] [-p[password]] [dbname]
username 与 password分别是 MySQL 的用户名与密码,mysql的初始管理帐号是root,没有密码,注意:这个root用户不是Linux的系统用户。MySQL默认用户是root,由于初始没有密码,第一次进时只需键入mysql即可。
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.18-standard
Copyright (c) 2000, 2010, 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>”提示符,恭喜你,安装成功!
设置密码
[root@localhost mysql]# mysqladmin -u root password 123456
增加了密码后的登录格式如下:
mysql -u root -p
Enter password: (输入密码)
其中-u后跟的是用户名,-p要求输入密码,回车后在输入密码处输入密码。
[root@localhost mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.18-standard
Copyright (c) 2000, 2010, 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>
4. 数据库的操作
查看有哪些数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
mysql>
使用数据库mysql,即进入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 |
| func |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| proc |
| procs_priv |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
17 rows in set (0.00 sec)
查看表user表的各字段属性
mysql> describe user;
+-----------------------+-----------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+-----------------------------------+------+-----+---------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Password | char(41) | NO | | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Reload_priv | enum('N','Y') | NO | | N | |
| Shutdown_priv | enum('N','Y') | NO | | N | |
| Process_priv | enum('N','Y') | NO | | N | |
| File_priv | enum('N','Y') | NO | | N | |
| Grant_priv | enum('N','Y') | NO | | N | |
| References_priv | enum('N','Y') | NO | | N | |
| Index_priv | enum('N','Y') | NO | | N | |
| Alter_priv | enum('N','Y') | NO | | N | |
| Show_db_priv | enum('N','Y') | NO | | N | |
| Super_priv | enum('N','Y') | NO | | N | |
| Create_tmp_table_priv | enum('N','Y') | NO | | N | |
| Lock_tables_priv | enum('N','Y') | NO | | N | |
| Execute_priv | enum('N','Y') | NO | | N | |
| Repl_slave_priv | enum('N','Y') | NO | | N | |
| Repl_client_priv | enum('N','Y') | NO | | N | |
| Create_view_priv | enum('N','Y') | NO | | N | |
| Show_view_priv | enum('N','Y') | NO | | N | |
| Create_routine_priv | enum('N','Y') | NO | | N | |
| Alter_routine_priv | enum('N','Y') | NO | | N | |
| Create_user_priv | enum('N','Y') | NO | | N | |
| ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | |
| ssl_cipher | blob | NO | | | |
| x509_issuer | blob | NO | | | |
| x509_subject | blob | NO | | | |
| max_questions | int(11) unsigned | NO | | 0 | |
| max_updates | int(11) unsigned | NO | | 0 | |
| max_connections | int(11) unsigned | NO | | 0 | |
| max_user_connections | int(11) unsigned | NO | | 0 | |
+-----------------------+-----------------------------------+------+-----+---------+-------+
37 rows in set (0.00 sec)
mysql>
查看表user中的记录
mysql> select * from user;
创建数据库db_test
mysql> create database db_test;
Query OK, 1 row affected (0.01 sec)
使用数据库db_test
mysql> use db_test;
Database changed
在当前数据库中创建表tb_test,该表含有两个字段Id,name
mysql> create table tb_test(Id int(8) not null primary key,name char(9));
Query OK, 0 rows affected (0.03 sec)
查看数据库中的表,显示刚创建的表tb_test
mysql> show tables;
+-------------------+
| Tables_in_db_test |
+-------------------+
| tb_test |
+-------------------+
1 row in set (0.00 sec)
mysql>
查看表tb_test的字段属性信息
mysql> describe tb_test;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| Id | int(8) | NO | PRI | | |
| name | char(9) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)
向表中添加记录
mysql> insert into tb_test values('1','Zhao');
Query OK, 1 row affected (0.00 sec)
mysql> insert into tb_test values('2','Qian');
Query OK, 1 row affected (0.00 sec)
查看表中的记录
mysql> select * from tb_test;
+----+------+
| Id | name |
+----+------+
| 1 | Zhao |
| 2 | Qian |
+----+------+
2 rows in set (0.00 sec)
mysql>
退出数据库
mysql> exit
Bye
[root@localhost mysql]#
关闭MySQL服务
[root@localhost mysql]# mysqladmin -u root -p shutdown
Enter password:
[root@localhost mysql]#
参考
http://blog.csdn.net/bat603/article/details/1063833
http://www.linuxidc.com/Linux/2009-03/18988.htm
http://www.jz123.cn/text/2937389.html
http://dev.mysql.com/doc/refman/5.1/zh/installing.html#linux-rpm
http://doc.linuxpk.com/42942.html
http://www.yesky.com/187/1754687.shtml