一、MYSQL安装
1.配置IP(必须配置IP,否则无法使用登陆)
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
BOOTPROTO=none
IPADDR=192.168.1.1
NETMASK=255.255.255.0
2.查看是否有安装软件包
mysql服务器安装教程[root@localhost ~]# rpm -q mysql
package mysql is not installed
3.把软件包拖进Linux
4.解压
[root@localhost Desktop]# tar -zxvf mysql-5.1. -C /usr/src/
5.配置
[root@localhost Desktop]# cd /usr/src/mysql-5.1.55/
[root@localhost mysql-5.1.55]# ./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312
6.安装
[root@localhost mysql-5.1.55]# make && make install
7.创建运行用户
[root@localhost mysql-5.1.55]# useradd -M -u 49 -s /sbin/nologin mysql (此用户名必须为mysql,不能更改)
8.建立主配置文件
[root@localhost mysql-5.1.55]# cp support-files/my-mediumf /etc/myf
9.初始化数据库
[root@localhost mysql-5.1.55]# cd /usr/local/mysql/bin/
[root@localhost bin]# ./mysql_install_db --user=mysql
使用刚刚创建的mysql用户来初始化数据库
10.更改属组和属主
[root@localhost bin]# chown -R root:mysql /usr/local/mysql/
[root@localhost bin]# chown -R mysql /usr/local/mysql/var/
11.优化执行路径
[root@localhost bin]# ln -s /usr/local/mysql/bin/* /usr/local/bin/
[root@localhost bin]# ln -s /usr/local/mysql/lib/mysql/* /usr/lib
[root@localhost bin]# ln -s /usr/local/mysql/include/mysql/* /usr/include/
12.添加系统服务
[root@localhost bin]# cd /usr/src/mysql-5.1.55/
[root@localhost mysql-5.1.55]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql-5.1.55]# chmod +x /etc/rc.d/init.d/mysqld
[root@localhost mysql-5.1.55]# chkconfig --add mysqld
[root@localhost mysql-5.1.55]# chkconfig mysqld on
[root@localhost mysql-5.1.55]# chkconfig --list mysqld
mysqld 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
13.启动服务
[root@localhost mysql-5.1.55]# service mysqld start
Starting MySQL. [确定]
[root@localhost mysql-5.1.55]# netstat -anpt | grep mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 17643/mysqld (mysqld服务默认占用TCP的3306号端口)
14.登陆MYSQLD服务器
添加密码:
[root@localhost mysql-5.1.55]# mysqladmin -u root password '123'
登陆方法一:
[root@localhost mysql-5.1.55]# mysql -u root -p
Enter password:
登陆方法二:
[root@localhost mysql-5.1.55]# mysql -u root -p123
二、使用MYSQL数据库
1.查看数据库
mysql> show databases; 查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
2.创建新库
mysql> create database s2t79; 创建名为s2t79的库
Query OK, 1 row affected (0.12 sec)
mysql> create database s2t80;
Query OK, 1 row affected (0.00 sec)
3.删除库
mysql> drop database s2t80; 删除名为s2t80的库
Query OK, 0 rows affected (0.02 sec)
4.切换目录
mysql> use s2t79 切换到库s2t79
Database changed
5.创建表,添加字段
mysql> create table hehe(id int(5),name char(15),gongzi int(6),QQ int(12));
创建名为hehe的表,其中有字段id、name、gongzi、QQ
6.查看表结构
mysql> desc hehe; 查看表hehe的结构
+--------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+-------+
| id | int(5) | YES | | NULL | |
| name | char(15) | YES | | NULL | |
| gongzi | int(6) | YES | | NULL | |
| QQ | int(12) | YES | | NULL | |
+--------+----------+------+-----+---------+-------+
4 rows in set (0.0
5 sec)
7.在表中添加记录
mysql> insert into hehe (id,name,QQ) values(1,'zhangsan',1012405802);
在表hehe中添加记录
8.查询数据记录
mysql> select * from hehe;
+------+----------+--------+------------+
| id | name | gongzi | QQ |
+------+----------+--------+------------+
| 1 | zhangsan | NULL | 1012405802 |
+------+----------+--------+------------+
1 row in set (0.00 sec)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论