MYSQL
# rpm -qa |grep mysql
# yum remove mysql mysql-server
# tar zxvf cmake-2.8.5.tar.gz -C /usr/local/src
# tar zxvf mysql-5.5.11.tar.gz -C /usr/local/src
安装开发包
# yum groupinstall "Development Libraries" "Development Tools" -y
安装cmake
# cd /usr/local/src/cmake-2.8.5
[root@teacher cmake-2.8.5]# ./configure
[root@teacher cmake-2.8.5]# gmake
[root@teacher cmake-2.8.5]# make install
安装mysql
# cd /usr/local/src/mysql-5.5.11/
[root@teacher mysql-5.5.11]# mkdir -pv /data/mysql
[root@teacher mysql-5.5.11]# groupadd mysql
[root@teacher mysql-5.5.11]# useradd -g mysql -s /sbin/nologin -d /data/mysql mysql
[root@teacher mysql-5.5.11]# chown mysql:mysql /data/mysql
[root@teacher mysql-5.5.11]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql55 \
> -DDEFAULT_CHARSET=utf8 \
> -DENABLED_LOCAL_INFILE=1 \
> -DMYSQL_DATADIR=/data/mysql \
> -DWITH_EXTRA_CHARSETS=all \
> -DWITH_READLINE=1 \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DMYSQL_TCP_PORT=3306 \
> -DDEFAULT_COLLATION=utf8_general_ci
如果因为缺包而出现错误,安装相应的包以后
# rm -f CMakeCache.txt
[root@teacher mysql-5.5.11]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql55 -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DDEFAULT_COLLATION=utf8_general_ci
[root@teacher mysql-5.5.11]# make
如果出现错误,解决错误以后先执行# make clean
然后再make
# make install
创建配置文件
[root@teacher mysql-5.5.11]# cd /usr/local/mysql55/support-files/
[root@teacher support-files]# cp -p my-medium.cnf /etc/my.cnf
初始化数据库
[root@teacher support-files]# cd /usr/local/mysql55/scripts/
[root@teacher scripts]# ls
mysql_install_db
[root@teacher scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql55 --datadir=/data/mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql55/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql55/bin/mysqladmin -u root -h teacher.uplook.com password 'new-password'
Alternatively you can run:
/usr/local/mysql55/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.
You can start the MySQL daemon with:
cd /usr/local/mysql55 ; /usr/local/mysql55/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql55/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/local/mysql55/scripts/mysqlbug script!
[root@teacher scripts]# cd /usr/local/mysql55/support-files/
[root@teacher support-files]# cp mysql.server /etc/init.d/mysqld
启动数据库
[root@teacher support-files]# cd /usr/local/mysql55/bin
You have new mail in /var/spool/mail/root
[root@teacher bin]# ./mysqld_safe --user=mysql &
# vim /etc/my.cnf
26 [mysqld]
27 datadir = /data/mysql
[root@teacher bin]# ./mysqld_safe --user=mysql &
[root@teacher bin]# netstat -altunp |grep :3306
tcp 0 0 :::3306 :::* LISTEN 10488/mysqld
# vim /etc/profile
export PATH=$PATH:/usr/local/mysql55/bin
-----------------------------
库
1)创建
mysql> show databases;
mysql> create database db1;
mysql> show databases;
2)删除数据库
mysql> drop database db1;
3) 查询
mysql> show databases;
mysql> create database db1;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db1 |
| mysql |
| performance_schema |
| test |
+--------------------+
-----------------------
表
mysql> use db1;
Database changed
mysql>
1) 创建
mysql> create table d1(id int);
mysql> show tables;
+---------------+
| Tables_in_db1 |
+---------------+
| d1 |
+---------------+
2)删除
mysql> drop table d1;
Query OK, 0 rows affected (0.00 sec)
3)修改结构
mysql> create table d1(id int,uid int,gid int);
修改列的数据类型
mysql> alter table d1 modify gid char(11);
mysql> desc d1;
添加一列
mysql> alter table d1 add ggid int;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc d1;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| uid | int(11) | YES | | NULL | |
| gid | char(11) | YES | | NULL | |
| ggid | int(11) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
mysql> alter table d1 add uuid int first;
mysql> desc d1;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| uuid | int(11) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| uid | int(11) | YES | | NULL | |
| gid | char(11) | YES | | NULL | |
| ggid | int(11) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
mysql> ALTER TABLE d1 ADD wwid INT AFTER id;
mysql> DESC d1;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| uuid | int(11) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| wwid | int(11) | YES | | NULL | |
| uid | int(11) | YES | | NULL | |
| gid | char(11) | YES | | NULL | |
| ggid | int(11) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
删除一列
mysql> ALTER TABLE d1 DROP wwid;
mysql> DESC d1;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| uuid | int(11) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| uid | int(11) | YES | | NULL | |
| gid | char(11) | YES | | NULL | |
| ggid | int(11) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
修改列的名字
mysql> ALTER TABLE d1 CHANGE uuid qqid CHAR(11);
mysql> DESC d1;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| qqid | char(11) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| uid | int(11) | YES | | NULL | |
| gid | char(11) | YES | | NULL | |
| ggid | int(11) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
修改表的名字
mysql> ALTER TABLE d1 RENAME dd1;
mysql> SHOW TABLES;
+---------------+
| Tables_in_db1 |
+---------------+
| d2 |
| dd1 |
+---------------+
查询表的结构
mysql> DESC dd1;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| qqid | char(11) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| uid | int(11) | YES | | NULL | |
| gid | char(11) | YES | | NULL | |
| ggid | int(11) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> SHOW COLUMNS FROM dd1;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| qqid | char(11) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| uid | int(11) | YES | | NULL | |
| gid | char(11) | YES | | NULL | |
| ggid | int(11) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+