首页 > 代码库 > MySQL安装
MySQL安装
MySQL安装
一、下载Mysql
http://mirrors.sohu.com/ ----搜狐开源镜像站
http://mirrors.163.com/ ----网易开源镜像站
[root@localhost src]# pwd
/usr/local/src
[root@localhost src]# wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73.tar.gz
--2015-01-06 22:30:03-- http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73.tar.gz
Resolving mirrors.sohu.com... 119.188.36.70
Connecting to mirrors.sohu.com|119.188.36.70|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 24023347 (23M) [application/octet-stream]
Saving to: “mysql-5.1.73.tar.gz”
100%[======================================>] 24,023,347 690K/s in 56s
2015-01-06 22:30:58 (422 KB/s) - “mysql-5.1.73.tar.gz” saved [24023347/24023347]
二、解刚才下载的Mysql包
[root@localhost src]# ll
total 23464
-rw-r--r--. 1 root root 24023347 Nov 5 2013 mysql-5.1.73.tar.gz
[root@localhost src]# tar zxf mysql-5.1.73.tar.gz
三、创建Mysql用户和组
[root@localhost src]# groupadd -g 400 mysql
[root@localhost src]# useradd -M -u 400 -g 400 -s /sbin/nologin mysql
[root@localhost src]# id mysql
uid=400(mysql) gid=400(mysql) groups=400(mysql)
四、编译安装MySQL
[root@localhost src]# cd mysql-5.1.73
[root@localhost mysql-5.1.73]# ./configure --prefix=/usr/local/mysql-5.1.73 --with-unix-socket-path=/usr/local/mysql-5.1.73/tmp/mysql.sock --localstatedir=/usr/local/mysql-5.1.73/data --enable-assembler --enable-thread-safe-client --with-mysqld-user=mysql --with-big-tables --without-debug --with-pthread --with-extra-charsets=complex --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static
./configure的最后提示信息,出现以下信息表示正确
Thank you for choosing MySQL!
Remember to check the platform specific part of the reference manual
for hints about installing MySQL on your platform.
Also have a look at the files in the Docs directory.
错误:checking for termcap functions library... configure: error: No curses/termcap library found
解决:[root@localhost ~]# yum install -y ncurses-devel
[root@localhost mysql-5.1.73]# make
make结束后的提示信息如下:
make[1]: Leaving directory `/usr/local/src/mysql-5.1.73/server-tools‘
Making all in win
make[1]: Entering directory `/usr/local/src/mysql-5.1.73/win‘
make[1]: Nothing to be done for `all‘.
make[1]: Leaving directory `/usr/local/src/mysql-5.1.73/win‘
[root@localhost mysql-5.1.73]# make install
make install结束后的提示信息如下:
make[2]: Leaving directory `/usr/local/src/mysql-5.1.73/win‘
make[1]: Leaving directory `/usr/local/src/mysql-5.1.73/win‘
五、拷贝配置文件及启动脚本
[root@localhost mysql-5.1.73]# cp support-files/my-medium.cnf /etc/my.cnf
[root@localhost mysql-5.1.73]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.1.73]# chmod 700 /etc/init.d/mysqld
[root@localhost mysql-5.1.73]# chkconfig --add mysqld
[root@localhost mysql-5.1.73]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
六、做符号链接,便于访问
[root@localhost mysql-5.1.73]# ln -s /usr/local/mysql-5.1.73/ /usr/local/mysql
[root@localhost mysql-5.1.73]# cd /usr/local/mysql
[root@localhost mysql]# ll
total 28
drwxr-xr-x. 2 root root 4096 Jan 6 23:55 bin
drwxr-xr-x. 3 root root 4096 Jan 6 23:54 include
drwxr-xr-x. 3 root root 4096 Jan 6 23:54 lib
drwxr-xr-x. 2 root root 4096 Jan 7 00:08 libexec
drwxr-xr-x. 10 root root 4096 Jan 7 00:08 mysql-test
drwxr-xr-x. 6 root root 4096 Jan 7 00:08 share
drwxr-xr-x. 5 root root 4096 Jan 7 00:08 sql-bench
七、进行mysql初始化
[root@localhost mysql]# ./bin/mysql_install_db --user=mysql
Installing MySQL system tables...
150107 0:15:52 [Warning] ‘--skip-locking‘ is deprecated and will be removed in a future release. Please use ‘--skip-external-locking‘ instead.
OK
Filling help tables...
150107 0:15:53 [Warning] ‘--skip-locking‘ is deprecated and will be removed in a future release. Please use ‘--skip-external-locking‘ instead.
OK
[root@localhost mysql]# ll
total 32
drwxr-xr-x. 2 root root 4096 Jan 6 23:55 bin
drwx------. 4 mysql root 4096 Jan 7 00:15 data
drwxr-xr-x. 3 root root 4096 Jan 6 23:54 include
drwxr-xr-x. 3 root root 4096 Jan 6 23:54 lib
drwxr-xr-x. 2 root root 4096 Jan 7 00:08 libexec
drwxr-xr-x. 10 root root 4096 Jan 7 00:08 mysql-test
drwxr-xr-x. 6 root root 4096 Jan 7 00:08 share
drwxr-xr-x. 5 root root 4096 Jan 7 00:08 sql-bench
八、设置目录属主
[root@localhost mysql]# chown -R mysql.mysql /usr/local/mysql
九、以脚本方式进行启动
[root@localhost mysql]# ./bin/mysqld_safe --user=mysql &
[1] 53830
[root@localhost mysql]# 150107 00:18:37 mysqld_safe Logging to ‘/usr/local/mysql/data/localhost.err‘.
150107 00:18:37 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
---回车
十、连接数据库
[root@localhost mysql]# ./bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73-log Source distribution
Copyright (c) 2000, 2013, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
mysql>
十一、优化mysql命令路径
[root@localhost mysql]# echo "export PATH=$PATH:/usr/local/mysql/bin/">>/etc/profile
[root@localhost mysql]# source /etc/profile
编译选项详解:
--prefix=/usr/local/mysql ----------设定mysql安装路径
--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock ----设定mysql socket文件存放目录
--localstatedir=/usr/local/mysql/data --设定mysql的数据文件存放位置
--enable-assembler -----允许汇编模式(优化性能),使用一些字符函数的汇编版本
--with-mysqld-ldflag=-all-static ---服务器使用静态库(优化性能),服务器端链接参数,本文示例为指定静态编译mysql服务器,(静态链接提高13%性能)
--with-client-ldflag=-all-static ---客户端使用静态库(优化性能),客户端链接参数,本文示例为指定静态编译mysql客户端,(静态链接提高13%性能)
--enable-thread-safe-client --以线程方式编译客户端
--with-mysqld-user=mysql --指定mysql运行的系统用户
--with-big-tables ----在32位平台上支持大于4G行的表
--without-debug ---使用非debug模式
--with-pthread --强制使用pthread线程序库编译
--with-extra-charsets=complex --服务器需要支持的字符集,有三种可能的值:空格间隔的一系列字符集名;complex ,包括不能动态装载的所有字符集;all,将所有字符集包括进二进制
-with-readline
--with-ssl ----启用SSL支持
-with-embedded-server ---编译embedded-server,构建嵌入式MySQL库
--enable-local-infile -----让mysql支持从本地文件导入数据库
--with-plugins=partition,innobase ----MySQL服务器端支持的存储引擎组件(默认为空),可选值较多:
partition:MySQL Partitioning Support;
daemon_example:This is an example plugin daemon;
ftexample:Simple full-text parser plugin;
archive:Archive Storage Engine;
blackhole:Basic Write-only Read-never tables;
csv:Stores tables in text CSV format,强制安装;
example:Example for Storage Engines for developers;
federated:Connects to tables on remote MySQL servers;
heap:Volatile memory based tables,强制安装;
ibmdb2i:IBM DB2 for i Storage Engine;
innobase:Transactional Tables using InnoDB;
innodb_plugin:Transactional Tables using InnoDB;
myisam:Traditional non-transactional MySQL tables,强制安装;
myisammrg:Merge multiple MySQL tables into one,强制安装;
ndbcluster:High Availability Clustered tables;)
MySQL安装