1.安装个cmake
2.将两个目录,一个是安装目录,一个数据存放目录
[root@ rhel5~]#mkdir -p /usr/local/mysql //安装mysql
[root@ rhel5~]#mkdir -p /usr/local/mysql/data //存放数据库
3.创建新的用户
[root@ rhel5~]groupadd mysql
[root@ rhel5~]useradd -r -g mysql mysql
4.安装mysql
[root@ rhel5 mysql-5.5.10]#cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\
-DMYSQL_DATADIR=/usr/local/mysql/data\
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DENABLED_LOCAL_INFILE=1
接下来 make && make install
5.设置
[root@ rhel5~]# cd /usr/local/mysql
[root@ rhel5 mysql]# chown -R root:mysql . //把当前目录中所有文件的所有者所有者设为root,所属组为mysql
[root@ rhel5 mysql]# chown -R mysql:mysql data
[root@ rhel5 mysql]# cp support-files/my-medium.cnf /etc/my.cnf //将mysql的启动服务添加到系统服务中
6.创建表
[root@ rhel5 mysql]# cd /usr/local/mysql
[root@ rhel5 mysql]# scripts/mysql_install_db --user=mysql
7.添加启动方式
[root@ rhel5 mysql]# cp support-files/mysql.server /etc/init.d/mysql //将mysql的启动服务添加到系统服务中
8.然后再用#service mysql start 来启动mysql即可。
mysql一些基本操作
1.备份数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| hello |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql> use hello;
Database changed
mysql> show tables;
+-----------------+
| Tables_in_hello |
+-----------------+
| children |
+-----------------+
1 row in set (0.00 sec)
mysql> describe children;
+---------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+----------------+
| childno | int(11) | NO | PRI | NULL | auto_increment |
| fname | varchar(30) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
+---------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
备份数据库
mysqldump [.......] --databases databasesname >name.sql
[luren@localhost ~]$ mysqldump -h 127.0.0.1 -u root -phello --databases hello >hello.sql
取回数据库
[luren@localhost ~]$ mysql -h 127.0.0.1 -u root -phello <hello.sql
备份数据表
mysqldump [......] database tables >children.sql
[luren@localhost ~]$ mysqldump -h 127.0.0.1 -u root -phello hello children >children.sql
取回数据表
mysql [......] database tables <children.sql