首页 > 代码库 > mysql详解安装
mysql详解安装
三种安装方式
1 二进制 解压就用
2 YUM/RPM 适用于很多台服务器安装,编译好后,做成RPM包 适用于yum仓库
3 编译安装 自定安装,相当于自己DIY了。。。5.1安装用make,5.5安装要用cmake
安装二进制详解演示!!
显示系统名、节点名称、操作系统的发行版号、操作系统版本、运行系统的机器 ID 号。
[root@sky-mysql ~]# uname -a
Linux sky-mysql 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
上传或者下载二进制包(官网或者网上,有很多)
[root@sky-mysql ~]# ll /home/sky00747/tools/
-rw-r--r--. 1 root root 186722932 Apr 2 2017 mysql-5.5.32-linux2.6-x86_64.tar.gz
解压缩
[root@sky-mysql tools]# tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz
[root@sky-mysql tools]# ll
total 182352
drwxr-xr-x. 13 root root 4096 Oct 21 22:41 mysql-5.5.32-linux2.6-x86_64
-rw-r--r--. 1 root root 186722932 Apr 2 2017 mysql-5.5.32-linux2.6-x86_64.tar.gz
拷贝到你要放到的目录下
[root@sky-mysql tools]#mkdir /application/
[root@sky-mysql tools]# cp -R mysql-5.5.32-linux2.6-x86_64 /application/
[root@sky-mysql tools]#ln -s mysql-5.5.32-linux2.6-x86_64/ ./mysql #创建一个软连接
模板文件
[root@sky-mysql mysql]# cd support-files/
[root@sky-mysql support-files]# ll
total 100
-rwxr-xr-x. 1 root root 1153 Oct 21 22:43 binary-configure
-rwxr-xr-x. 1 root root 4528 Oct 21 22:43 config.huge.ini
-rwxr-xr-x. 1 root root 2382 Oct 21 22:43 config.medium.ini
-rwxr-xr-x. 1 root root 1626 Oct 21 22:43 config.small.ini
-rw-r--r--. 1 root root 773 Oct 21 22:43 magic
-rw-r--r--. 1 root root 4691 Oct 21 22:43 my-huge.cnf
-rw-r--r--. 1 root root 19759 Oct 21 22:43 my-innodb-heavy-4G.cnf
-rw-r--r--. 1 root root 4665 Oct 21 22:43 my-large.cnf
-rw-r--r--. 1 root root 4676 Oct 21 22:43 my-medium.cnf
-rw-r--r--. 1 root root 2840 Oct 21 22:43 my-small.cnf
-rwxr-xr-x. 1 root root 1061 Oct 21 22:43 mysqld_multi.server
-rwxr-xr-x. 1 root root 839 Oct 21 22:43 mysql-log-rotate
-rwxr-xr-x. 1 root root 10880 Oct 21 22:43 mysql.server
-rwxr-xr-x. 1 root root 1326 Oct 21 22:43 ndb-config-2-node.ini
drwxr-xr-x. 2 root root 4096 Oct 21 22:43 solaris
创建存放data文件的目录
[root@sky-mysql ~]# mkdir /var/lib/mysql
拷贝模板文件(就是配置文件),根据自己需求拷贝把。也可以后慢慢改改
[root@sky-mysql support-files]# cp my-large.cnf ./my.cnf
这样拷贝会有很多的注释。。根据自己喜好吧。。。我就不注释了
注释参数 cat my-large.cnf|egrep -v "#|^$" >/etc/my.cnf
vim my.cnf
在[mysqld]中
添加datadir = /var/lib/mysql
cp ./my.cnf /var/lib/mysql
#默认是可以拷贝到/etc/my.cnf
创建mysql用户,但是不能让这个用户登录
[root@sky-mysql support-files]# useradd mysql -s /sbin/nologin -M
将目录授权给mysql用户与组
[root@sky-mysql support-files]# chown -R mysql.mysql /var/lib/mysql/
[root@sky-mysql support-files]# ll /var/lib/mysql/
total 8
-rw-r--r--. 1 mysql mysql 4689 Oct 21 23:25 my.cnf
配置启动文件
[root@sky-mysql support-files]# cp mysql.server /etc/init.d/mysqld
初始化(就是生产mysql的表)
./scripts/mysql_install_db --defaults-file=/var/lib/mysql/my.cnf --user=mysql
启动mysql
可以通过/etc/init.d/mysqld start
还有一种
[root@sky-mysql mysql]# cd /application/mysql/bin/
[root@sky-mysql mysql]#./bin/mysqld_safe &
如果my.cnf 在/etc/下,这样启动就可以。但是我们的配置文件在/var/lib/mysql/下,就要指定文件了
[root@sky-mysql mysql]#./bin/mysqld_safe --defaults-file=/var/lib/mysql/my.cnf &
查看是否启动
查看端口
[root@sky-mysql bin]# ss -lntup |grep 3306
tcp LISTEN 0 50 *:3306 *:* users:(("mysqld",27975,11))
查看任务
[root@sky-mysql bin]# ps -ef |grep mysqld
root 27697 27448 0 23:56 pts/0 00:00:00 /bin/sh ./mysqld_safe --defaults-file=/var/lib/mysql/my.cnf
mysql 27975 27697 1 23:56 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/var/lib/mysql/my.cnf --basedir=/usr/local/mysql --datadir=/var/lib/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/lib/mysql/sky-mysql.err --pid-file=/var/lib/mysql/sky-mysql.pid --socket=/tmp/mysql.sock --port=3306
启动mysql
[root@sky-mysql bin]# echo ‘export PATH=/application/mysql/bin:$PATH‘ >> /etc/profile
[root@sky-mysql bin]# tail -1 /etc/profile
export PATH=/application/mysql/bin:$PATH
[root@sky-mysql bin]# source /etc/profile
加入环境变量就可直接启动mysql了
[root@sky-mysql bin]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.32-log MySQL Community Server (GPL)
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>
===============================编译安装=====================
安装5.5
检查依赖包
yum install ncurses-devel libaio-devel -y
rpm -qa ncurses-devel libaio
如果安装5.5 需要一个软件 cmake
https://cmake.org/files/v3.7/cmake-3.7.2.tar.gz
tar xf cmake-3.6.3.tar.gz
cd cmake-3.6.3.tar.gz
./configure
gmake
gmake install
==========安装mysql===========
创建用户
useradd mysql -s /sbin/nologin -M
cd mysql-5.5.32
编译
cd mysql-5.5.32
编译
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \
-DMYSQL_DATADIR=/application/mysql-5.5.32/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED-LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
make && make install &
ln -s /application/mysql-5-5.32/ /application/mysql
安装完成
拷贝模板
cp support-files/my-small.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf‘? y
配置环境变量
echo ‘export PATH=/application/mysql/bin:$PATH‘ >> /etc/profile
tail -1 /etc/profile
source /etc/profile
echo $PATH
/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
一定要排在最前面
chown -R mysql.mysql /application/mysql/data/
chmod -R 1777 /tmp/
初始化
cd /application/mysql/scripts/
./mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql
init.d启动脚本
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld start
查看端口
netstat -lntup|grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 19011/mysqld
就能登录了
启动mysql
mysql详解安装