MySQL 安装(二进制安装模式)


MySQL 安装(RPM安装模式)及目录结构

MySQL 安装(二进制安装模式)

MySQL 安装(源码安装模式)


本篇使用二进制模式安装:


查看当前是几位系统:file/sbin/init



各下载地址:

Mysql官网下载:

       http://dev.mysql.com/downloads/mysql/  (默认选择当前系统)

       http://dev.mysql.com/downloads/mirrors.html  (其他镜像地址)

Oracle官方下载:https://edelivery.oracle.com/

FTP下载:

http://ftp.iij.ad.jp/pub/db/mysql/Downloads/

http://mirrors.sohu.com/mysql/

http://mysql.mirror.kangaroot.net/Downloads/


看到那么多,到底下载哪个?哪个才是二进制的包?

看官方说明:http://dev.mysql.com/doc/refman/5.1/en/binary-installation.html

二进制版本格式: mysql-VERSION-OS.tar.gz (如:mysql-5.6.23-linux.tar.gz)


当前示例的mysql下载地址(size:289M)

http://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.6/mysql-5.6.23-linux-glibc2.5-i686.tar.gz


解压路径:

cd /usr/local/src/

tar zxvfmysql-5.6.23-linux-glibc2.5-i686.tar.gz


移到目录/usr/local/,并更名为mysql:

mv mysql-5.6.23-linux-glibc2.5-i686 /usr/local/mysql


添加用户及组:

groupadd mysql

useradd -g mysql mysql


设置mysql目录的所有者及组:

chown -R mysql:mysql mysql



初始化mysql:

/usr/local/mysql/scripts/mysql_install_db--user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

MySQL 安装(二进制安装模式)_第1张图片


上图中第一个和最后一个红框中,参考提示。复制服务和配置文件到系统配置文件中:

cp/usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

cp /usr/local/mysql/support-files/my-default.cnf/etc/my.cnf


ln -s /usr/local/mysql/bin/mysql /usr/bin

编辑mysql配置文件添加以下参数:vi /etc/my.cnf

[mysqld]

basedir =/usr/local/mysql

datadir =/usr/local/mysql/data

port = 3306

server_id = 1


启动mysqld服务:

/etc/rc.d/init.d/mysqld start


启动mysqld服务的另一种方法(看上图也提示):

/usr/local/mysql/bin/mysqld_safe&

#这是在Unix和NetWare中推荐启动mysqld服务的启动文件。

#更多参考:mysqld_safe— MySQL Server Startup Script


设置mysql的root密码:

/usr/local/mysql/bin/mysqladmin-u root password 'mysql'



为了安全,使用mysql_secure_installation来设置:

/usr/local/mysql/bin/mysql_secure_installation

#(内容截取如下:)

NOTE: RUNNINGALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

…………

Entercurrent password for root (enter for none): #若已设置root密码,则输入,否则留空

…………

You alreadyhave a root password set, so you can safely answer 'n'.

Changethe root password? [Y/n] y       #是否改变root密码?(因为我已设置过)

New password:

Re-enter newpassword:

…………

Removeanonymous users? [Y/n] y      #是否移除匿名用户?

…………

Disallowroot login remotely? [Y/n] y     #是否禁止root远程登录?

…………

Removetest database and access to it? [Y/n] n   #是否移除测试数据库?

…………

Reloadprivilege tables now? [Y/n] y     #是否重新加载权限表?

…………

Cleaning up... #完成!



启动mysql后,客户端与服务器进行通信的套接字文件路径:

/tmp/mysql.sock


以mysqld_safe启动mysqld服务时会生成日志文件:

/var/log/mysqld.log



安装基本完成!

cd /usr/local/src
tar zxvf mysql-5.6.30-linux-glibc2.5-i686.tar.gz

mv mysql-5.6.30-linux-glibc2.5-i686 /usr/local/mysql

cd /usr/local

groupadd mysql
useradd -g mysql mysql
chown -R mysql:mysql mysql

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

ln -s /usr/local/mysql/bin/mysql /usr/bin


vi /etc/my.cnf

basedir =/usr/local/mysql
datadir =/usr/local/mysql/data
port = 3306

/etc/rc.d/init.d/mysqld start

/usr/local/mysql/bin/mysqladmin -u root password 'mysql'


现在删除mysql(二进制安装模式直接删除所有mysql相关文件):

rm -f/etc/init.d/mysqld

rm -f/etc/my.cnf

find / -namemysql     #搜索mysql目录,接着进行删除

find / -name"mysql*"   #先删除上面找出来的,再找出继续删除,注意要不要删除!




你可能感兴趣的:(MYSQL,MYSQL,安装升级)