系统centos6.7

在安装前要先确定系统是否已经安装了其他版本的MySQL,如已安装其他版本的MySQL,需先删除后再安装新版本。</span></span>

<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;">1.删除MySQL的lib库,服务文件</span></span>

<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;">&nbsp;<span style="text-align: left; color: rgb(0, 0, 0); text-transform: none; line-height: 21px; text-indent: 0px; letter-spacing: normal; font-style: normal; font-variant: normal; font-weight: normal; word-spacing: 0px; float: none; display: inline !important; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">rpm&nbsp;-qa&nbsp;mysql*&nbsp;|xargs&nbsp;rpm&nbsp;-e&nbsp;--nodeps</span></span></span>

<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;">&nbsp;2.&nbsp;执行find命令,查找MySQL的残留文件,然后运行&ldquo;rm -rf&nbsp;文件名&rdquo;删除残留的MySQL文件</span></span>

<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;"><span lang="EN-US" style="background-color: inherit;"><font style="background-color: inherit;">&nbsp;find / -name mysql |xargs rm -rf</font></span></span></span>

find / -name my.cnf* |xargs rm -rf
<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;">yum install libaio -y

&nbsp;下载地址

[ftp://ftp.stu.edu.tw/pub/Unix/Database/Mysql/Downloads/](ftp://ftp.stu.edu.tw/pub/Unix/Database/Mysql/Downloads/)</span></span>

<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;">1.安装mysql

groupadd mysql

useradd -r -g mysql mysql

mkdir -p /data/mysql/data/

mkdir -p /data/mysql/log/

chown -R mysql.mysql&nbsp; /data/mysql/

&nbsp;rpm -ivh [ftp://ftp.stu.edu.tw/pub/Unix/Database/Mysql/Downloads/MySQL-5.6/MySQL-server-5.6.32-1.el6.x86_64.rpm](ftp://ftp.stu.edu.tw/pub/Unix/Database/Mysql/Downloads/MySQL-5.6/MySQL-server-5.6.32-1.el6.x86_64.rpm)

&nbsp;rpm -ivh [ftp://ftp.stu.edu.tw/pub/Unix/Database/Mysql/Downloads/MySQL-5.6/MySQL-client-5.6.32-1.el6.x86_64.rpm](ftp://ftp.stu.edu.tw/pub/Unix/Database/Mysql/Downloads/MySQL-5.6/MySQL-client-5.6.32-1.el6.x86_64.rpm)

&nbsp;rpm -ivh [ftp://ftp.stu.edu.tw/pub/Unix/Database/Mysql/Downloads/MySQL-5.6/MySQL-devel-5.6.32-1.el6.x86_64.rpm](ftp://ftp.stu.edu.tw/pub/Unix/Database/Mysql/Downloads/MySQL-5.6/MySQL-devel-5.6.32-1.el6.x86_64.rpm)

&nbsp;rpm -ivh [ftp://ftp.stu.edu.tw/pub/Unix/Database/Mysql/Downloads/MySQL-5.6/MySQL-shared-compat-5.6.32-1.el6.x86_64.rpm](ftp://ftp.stu.edu.tw/pub/Unix/Database/Mysql/Downloads/MySQL-5.6/MySQL-shared-compat-5.6.32-1.el6.x86_64.rpm)

&nbsp;

mysql使用rpm安装使用默认信息如下:

1)数据库默认目录 /var/lib/mysql/

2)配置文件 /usr/share/mysql (mysql.server命令及配置文件 )

3)相关命令 /usr/bin/&nbsp; (mysqladmin&nbsp; mysqldump)

4)启动脚本 /etc/rc.d/init.d/mysql start

5)默认端口是3306</span></span>

<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;">安装完mysqlserver时,会提示以下信息:

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !

You will find that password in &#39;/root/.mysql_secret&#39;.&nbsp;

&nbsp;You must change that password on your first connect,no other statement but &#39;SET PASSWORD&#39; will be accepted.

See the manual for the semantics of the &#39;password expired&#39; flag.

&nbsp;Also, the account for the anonymous user has been removed. In addition, you can run:

&nbsp; /usr/bin/mysql_secure_installation

which will also give you the option of removing the test database. This is strongly recommended for production servers.

&nbsp;New default config file was created as /usr/my.cnf andwill be used by default by the server when you start it. You may edit this file to change server settings

&nbsp;#####

<span style="color: rgb(255, 0, 0);">执行</span>

&nbsp;chown -R mysql:mysql /var/lib/mysql

&nbsp;chmod -R 777 /var/lib/mysql

chown mysql.mysql /usr/my.cnf

自定义mysql

修改<span style="color: rgb(255, 0, 0);">vi /usr/my.cnf</span>---删除所有内容,添加以下内容</span></span>

<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;">[mysqld]

port=3306

datadir =/data/mysql/data

socket = /data/mysql/mysql.sock

pid-file=/data/mysql/mysql.pid

user=mysql

character-set-server=utf8

lower_case_table_names= 1

max_connect_errors=500

max_connections=2000

binlog_format=mixed

lower_case_table_names=1

skip_name_resolve = 1</span></span>


group_concat_max_len = 102400





open_files_limit = 102400

#log-setup

expire_logs_days=30

long_query_time=3

slow_query_log=1

slow_query_log_file=/data/mysql/log/slow_query.log

log_error=/data/mysql/log/error3306.log

log-bin=/data/mysql/log/logbin.log

log-error=/data/mysql/log/logerr.log

log_output=file

#general_log=ON

#general_log_file=/data/mysql/log/general3306.log

innodb_log_file_size=256M

innodb_log_files_in_group=3

#master-SyncSetup

server-id = 1

sync_binlog = 2

innodb_support_xa = 1

log-slave-updates

log_bin_trust_function_creators=1

auto_increment_offset=1

auto_increment_increment=1

innodb_flush_log_at_trx_commit=2

sql_mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_AUTO_VALUE_ON_ZERO




<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;">#######

<span style="text-align: left; color: rgb(0, 0, 0); text-transform: none; line-height: 24px; text-indent: 0px; letter-spacing: normal; font-style: normal; font-variant: normal; font-weight: normal; word-spacing: 0px; float: none; display: inline !important; white-space: normal; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">因为我们自定义了路径和参数,所以</span><span style="text-align: left; color: rgb(0, 0, 0); text-transform: none; line-height: 24px; text-indent: 0px; letter-spacing: normal; font-style: normal; font-variant: normal; font-weight: normal; word-spacing: 0px; white-space: normal; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">需要<span style="text-align: left; color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">初始化数据</span>。</span>

# <span style="text-align: left; color: rgb(255, 0, 0); text-transform: none; line-height: 21px; text-indent: 0px; letter-spacing: normal; font-style: normal; font-variant: normal; font-weight: normal; word-spacing: 0px; float: none; display: inline !important; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">mysql_install_db&nbsp;--defaults-</span><span style="text-align: left; color: rgb(255, 0, 0); text-transform: none; line-height: 21px; text-indent: 0px; letter-spacing: normal; font-style: normal; font-variant: normal; font-weight: normal; word-spacing: 0px; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: inherit; -webkit-text-stroke-width: 0px;">file</span><span style="text-align: left; color: rgb(255, 0, 0); text-transform: none; line-height: 21px; text-indent: 0px; letter-spacing: normal; font-style: normal; font-variant: normal; font-weight: normal; word-spacing: 0px; float: none; display: inline !important; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">=</span><span style="text-align: left; color: rgb(255, 0, 0); text-transform: none; line-height: 21px; text-indent: 0px; letter-spacing: normal; font-style: normal; font-variant: normal; font-weight: normal; word-spacing: 0px; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: inherit; -webkit-text-stroke-width: 0px;">/usr/my</span><span style="text-align: left; color: rgb(255, 0, 0); text-transform: none; line-height: 21px; text-indent: 0px; letter-spacing: normal; font-style: normal; font-variant: normal; font-weight: normal; word-spacing: 0px; float: none; display: inline !important; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">.cnf&nbsp;&nbsp;</span></span></span>

<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;">要过一会才完成,可以查看进度tail -f /data/mysql/log/logerr.log

完成后提示

###

&nbsp; /usr/bin/mysqladmin -u root password &#39;new-password&#39;

&nbsp; /usr/bin/mysqladmin -u root -h localhost.localdomain password &#39;new-password&#39;

Alternatively you can run:

&nbsp; /usr/bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default.&nbsp; This is

strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

&nbsp; cd /usr ; /usr/bin/mysqld_safe &amp;

##################</span></span>

<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;">现在在启动mysql

/usr/bin/mysqld_safe --defaults-file=/usr/my.cnf&nbsp; &amp;</span></span>

<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;">初始化root密码:

因为我们在my.cnf自定义mysql.sock路径,所有要加mysql.sock路径

登录用

<span style="color: rgb(255, 0, 0);">mysql -S /data/mysql/mysql.sock</span></span></span>

<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;">配置允许登陆。

mysql&gt;use mysql;

mysql&gt; select host,user,password from user;&nbsp; - 查看现有用户,密码及允许连接的主机

mysql&gt; update user set password=password(&#39;123456&#39;) where user=&#39;root&#39;;&nbsp; -----修改root密码

mysql&gt; grant all privileges on *.* to [root@&#39;127.0.0.1&#39;](mailto:root@) identified by &#39;123456&#39;;&nbsp; ---本地127.0.0.1访问

mysql&gt; grant all privileges on *.* to [root@&#39;localhost&#39;](mailto:root@) identified by &#39;123456&#39;; ---本地localhost访问

mysql&gt; grant all privileges on *.* to [root@&#39;%&#39;](mailto:root@) identified by &#39;123456&#39;;&nbsp;&nbsp;&nbsp;&nbsp; ---&lsquo;%&rsquo; 任意ip访问

mysql&gt; flush privileges;

mysql&gt; exit</span></span>

<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;">这样就可以本地登录了。

mysql -S /data/mysql/mysql.sock -uroot -p</span></span>

<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;">加入自启动

chkconfig --add mysql

chkconfig mysql on</span></span>

关闭服务:

mysqladmin -S /data/mysql/mysql.sock -u root -p shutdown
<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;">如果用mysql默认的my.cnf文件,就可以用如下方法--初始化root密码

方法1:

第一次登陆,查看默认root密码:

cat /root/.mysql_secret&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #查看root账号的初始密码,会出现下述所示信息

# The random password set for the root user at Mon Aug 25 10:26:57 2014 (local time): ZFRmqNPoFH3aO5PU

或者cat /root/.mysql_secret |awk -F &#39;:&#39; &#39;{print $4}&#39;

mysql -uroot -pZFRmqNPoFH3aO5PU&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #使用root账号登陆MySQL

mysql&gt; set password=password(&#39;123456&#39;);&nbsp;&nbsp; #更改MySQL密码,注意;不可少</span></span>

<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;">exit  #退出

mysql -uroot -p123456&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #使用新密码登陆

进入mysql&gt;</span></span>

<span style="font-size: 16px;"><span style="font-family: times new roman,times,serif;">方法2:更换root密码, mysql_secure_installation,

[root@centos6 /]# mysql_secure_installation

Enter current password for root (enter for none):&nbsp;&nbsp;&nbsp; #输入上面/root/.mysql_secret的初始密码

OK, successfully used password, moving on..

Change the root password? [Y/n] Y

New password:

Re-enter new password:

Password updated successfully!

Remove anonymous users? [Y/n] Y&nbsp;&nbsp;&nbsp; &lt;&ndash; 是否删除匿名用户,生产环境建议删除,

Disallow root login remotely? [Y/n] N&nbsp;&nbsp;&nbsp; &lt;&ndash;是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止

Remove test database and access to it? [Y/n] Y&nbsp; &lt;&ndash; 是否删除test数据库

Reload privilege tables now? [Y/n]&nbsp;&nbsp; ] &lt;&ndash; 是否重新加载权限表,直接回车

All done!&nbsp; If you&#39;ve completed all of the above steps, your MySQL

installation should now be secure.

Thanks for using MySQL!

&nbsp;在输入mysql -uroot -p,就可以用新密码了

&nbsp;#############</span></span>

&nbsp;