mysql是数据库文件(存储数据);
1.下载(猿课论坛链接或者官网)合适版本(官网5.7,我们学习用5.1);免编译的二进制包。源码包就需要编译器编译成能够支持的二进制文件。注意下载的时候和系统位数(32位/64位)的区分
[root@aminglinux ~]# cd/usr/local/src/
[root@aminglinux src] wgethttp://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz
[root@aminglinux src]# ls
[root@aminglinux src]# du -shmysql-5.1.73-linux-x86_64-glibc23.tar.gz
2.解压 tar
[root@aminglinux src]# tar zxvf mysql-5.1.73-linux-x86_64-glibc23.tar.gz
[root@aminglinux src]# ls
mysql-5.1.73-linux-x86_64-glibc23 mysql-5.1.73-linux-x86_64-glibc23.tar.gz
3、建立mysql用户
创建运行mysql的账户不需要登陆 可不创建家目录
[root@localhost src]# useradd -s /sbin/nologin -M mysql
[root@aminglinux src]# ls /home 验证
aming jishan mysql user1 user2 user4 user9
4.移动并重命名。把解压完的数据移动到/usr/local/mysql
[root@aminglinux src]# mv mysql-5.1.73-linux-x86_64-glibc23 /usr/local/mysql 移动带重命名 之前这个目录不存在/usr/local/mysq
查看mysql文件
[root@aminglinux src]# ls /usr/local/mysql 验证 /usr/local/mysql等于mysql-5.1.73-linux-x86_64-glibc23
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files
5.初始化数据库
进入 cd /usr/local/mysql
[root@aminglinux src]# cd /usr/local/mysql
创建存放mysql数据的文件夹并更改权限
[root@aminglinux mysql]# mkdir -p /data/mysql
[root@aminglinux mysql]# chown -R mysql /data/mysql
[root@aminglinux mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql 初始化完成就有两个“ok”。也可以用命令 echo$? 检测,如果输出为0 表示成功。
Installing MySQL system tables...
OK
Filling help tables...
OK
备注:如果是版本mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz编译会报错,#因为我的linux是最小化安装的,这里报错缺少共享库文件,没关系,我们安装一下就可以了。 yum install -y libaio
[root@aminglinux mysql]# ./scripts/mysql_install_db--user=mysql --datadir=/dat a/mysql
Installing MySQL system tables..../bin/mysqld: errorwhile loading shared librar ies:libaio.so.1: cannot open shared object file: No such file or directory
[root@aminglinux mysql]# ./scripts/mysql_install_db--user=mysql --datadir=/data/mysql
Installing MySQL system tables..../bin/mysqld: errorwhile loading shared libraries: libaio.so.1: cannot open shared object file: Nosuch file or directory
[root@aminglinux mysql]# yum install -y libaio 5.5版本安装这个yum install -y libaio*
6.拷贝配置文件,放在相应的目录里面。
[root@aminglinux mysql]# cd support-files/ 将配置文件放在相应的目录里面。配置文件存放目录
[root@aminglinux support-files]# ls
binary-configure my-huge.cnf mysqld_multi.server
config.huge.ini my-innodb-heavy-4G.cnf mysql-log-rotate
config.medium.ini my-large.cnf mysql.server
config.small.ini my-medium.cnf ndb-config-2-node.ini
magic my-small.cnf
[root@aminglinux support-files]# cp my-large.cnf /etc/my.cnf 先将my-large.cnf拷贝到etc/my.cnf下并覆盖之前的配置文件
cp:是否覆盖"/etc/my.cnf"? y
备注:如果是版本mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz需要执行cpmy-default.cnf /etc/my.cnf
[root@aminglinux support-files]# ls
binary-configure magic my-default.cnf mysqld_multi.server mysql-log-rotate mysql.server
[root@aminglinux support-files]# cp my-large.cnf /etc/my.cnf
cp: 无法获取"my-large.cnf"的文件状态(stat): 没有那个文件或目录
-bash: syntax error near unexpected token `(‘
[root@aminglinux support-files]# cp my-default.cnf/etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
[root@aminglinux support-files]# vim my-large.cnf
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU‘s*2 forthread_concurrency
thread_concurrency = 8
# Don‘t listen on a TCP/IP port at all.This can be a security enhancement,
# if all processes that need to connect tomysqld run on the same host.
# All interaction with mysqld must be madevia Unix sockets or named pipes.
# Note that using this option withoutenabling named pipes on Windows
# (via the "enable-named-pipe"option) will render mysqld useless!
#
#skip-networking
# Replication Master Server (default)
# binary logging is required forreplication
#log-bin=mysql-bin主从的时候用到 前面输入#注释
# binary logging format - mixed recommended
#binlog_format=mixed
# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master ifomitted
#server-id = 1
7.拷贝启动脚本。加入到系统服务列表中并启动服务。
[root@aminglinux support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chmod 755 /etc/init.d/mysqld电子书上的说明,视频上介绍无
8、修改启动脚本
[root@aminglinux support-files]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
9、把启动脚本加入系统服务项,并设定开机启动,启动mysql
[root@aminglinux support-files]# chkconfig --add mysqld 加入服务列表
[root@aminglinux support-files]# chkconfig mysqld on
[root@aminglinux support-files]# /etc/init.d/mysqld startservice mysqld start
Starting MySQL.. SUCCESS!
[root@aminglinux support-files]# netstat -lnp |grep mysql 验证成功
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 3418/mysqld
unix 2 [ ACC ] STREAM LISTENING 29567 3418/mysqld /tmp/mysql.sock
[root@aminglinux support-files]#
5.6安装可以参考这个
http://blog.csdn.net/noob_f/article/details/51399335
5.7实战安装mysql-5.7.12可以参考这个
http://ask.apelearn.com/question/13004
原文地址:http://jishan.blog.51cto.com/12548249/1905019