知识点023-mysql-5.5.49版本二进制安装

来源:互联网 时间:2018-03-01

Mysql安装步骤:


系统版本:


[[email protected] ~]# cat /etc/redhat-release


CentOS release 6.8 (Final)

1、上传MySQL二进制安装包:

https://pan.baidu.com/disk/home#category/type=6&vmode=list###-网盘下载地址


[[email protected]~]#cd/home/oldboy/tools/
[[email protected]]#rz-y
[[email protected]]#ll-h
总用量178M-rw-r--r--1rootroot178M5月162016mysql-5.5.49-linux2.6-x86_64.tar.gz

2、检查当前系统中是否存在mysql用户,如果不存在就新建mysql用户,然后解压缩mysql的安装包:


[[email protected]]#useradd-s/sbin/nologin-Mmysql
[[email protected]]#idmysql
uid=501(mysql)gid=501(mysql)组=501(mysql)
[[email protected]]#tarxfmysql-5.5.49-linux2.6-x86_64.tar.gz

# 由于是二进制安装包,不需要进行make和make install


# 只要把解压过后的目录移动到/application/下即可


[[email protected]]#mkdir-p/application
[[email protected]]#mvmysql-5.5.49-linux2.6-x86_64/application/mysql-5.5.49
[[email protected]]#cd/application/
[[email protected]]#ln-s/application/mysql-5.5.49//application/mysql
[[email protected]]#ls-l
总用量8l
rwxrwxrwx1rootroot265月3023:11mysql->/application/mysql-5.5.49/
drwxr-xr-x13rootroot40965月3023:09mysql-5.5.49

# 授权mysql管理数据库文件


# 授权到底是在初始化后还是在初始化前,需要进行测试


[[email protected]]#chown-Rmysql.mysql/application/mysql/

3、初始化mysql数据库


# 初始化过程中出现2个OK就表示成功,出现error要解决,出现warnnig可以忽略


# 如果初始化失败,需要删除/application/mysql/data/目录下所有数据文件


# 之后解决报错,再次初始化


# 如果/tmp目录权限不对,也会导致mysql初始化失败,/tmp目录权限为1777


[[email protected]]#/application/mysql/scripts/mysql_install_db--basedir=/application/mysql--datadir=/application/mysql/data/--user=mysql
Installing
MySQLsystemtables...OK
Fillinghelptables...OK
Tostartmysqldatboottimeyouhavetocopysupport-files/mysql.servertotherightplaceforyoursystemPLEASEREMEMBERTOSETAPASSWORDFORTHEMySQLrootUSER!
Todoso,starttheserver,thenissuethefollowingcommands:

4、生成mysql配置文件


# mysql配置文件位置


# 一般虚拟机使用my-medium.cnf和my-small.cnf


# 学习参数使用my-innodb-heavy-4G.cnf


[[email protected]]#cd/application/mysql/support-files/
[[email protected]]#ll
总用量96-rw-r--r--1mysqlmysql4691Jun192013my-huge.cnf#巨大配置
-rw-r--r--1mysqlmysql19759Jun192013my-innodb-heavy-4G.cnf#重大配置
-rw-r--r--1mysqlmysql4665Jun192013my-large.cnf#比较大配置
-rw-r--r--1mysqlmysql4676Jun192013my-medium.cnf#最小配置
-rw-r--r--1mysqlmysql2840Jun192013my-small.cnf#比较小配置

# 覆盖系统自带的mysql配置文件


[[email protected]]#cpmy-small.cnf/etc/my.cnf
cp:是否覆盖"/etc/my.cnf"?y

5、更改mysql默认启动文件里的目录位置


由于是我们自定义mysql二进制包安装路径在/application/mysql目录下,但是,二进制默认的安装路径是/usr/local/mysql,这可以通过mysql启动文件看出来:



那么我们需要将该启动文件里的/usr/local/mysql变成/application/mysql目录。


[[email protected]]#sed-i‘s#/usr/local/mysql#/application/mysql#g‘/application/mysql/bin/mysqld_safe

之后,后台启动mysql


[[email protected]]#/application/mysql/bin/mysqld_safe&
[1]1944
15102109:37:28mysqld_safeLoggingto‘/application/mysql/data/db01.err‘.
15102109:37:28mysqld_safeStartingmysqlddaemonwithdatabasesfrom/application/mysql/data

# 按下回车键


检查mysql的3306端口:


[[email protected]]#lsof-i:3306
COMMANDPIDUSERFDTYPEDEVICESIZE/OFFNODENAMEmysqld2162mysql10uIPv4189220t0TCP*:mysql(LISTEN)

6、配置环境变量


[[email protected]]#tail-1/etc/profile
exportPATH=/application/mysql/bin:$PATH
[[email protected]]#source/etc/profile
[[email protected]]#whichmysql
/application/mysql/bin/mysql

7、登录mysql


[[email protected]]#mysql
WelcometotheMySQLmonitor.Commandsendwith;or/g...mysql>exit
Bye

8、安装过程的排错


# mysql的错误日志,在/application/mysql/data目录下以主机名命名的err文件


[[email protected]]#pwd
/application/mysql/data
[[email protected]]#ll总用量28692-rw-r-----1mysqlroot19955月2919:15db01.err

9、配置科学启动mysql


[[email protected]]#pwd
/application/mysql/support-files

# mysql.server是一个启动脚本


[[email protected]]#cpmysql.server/etc/init.d/mysqld

# 再次改变mysql的默认路径


[[email protected]]#sed-i‘s#/usr/local/mysql#/application/mysql#g‘/etc/init.d/mysqld

# 增加执行权限


[[email protected]]#chmod+x/etc/init.d/mysqld

# 停止之前启动的mysql,直到提示“mysqld: no process killed”


# 使用killall停止mysql,生产环境不要使用pkill停止mysql,影响太大


[[email protected]]#killallmysqld
15102110:01:47mysqld_safemysqldfrompidfile/application/mysql/data/db01.pid
ended
[1]+Done/application/mysql/bin/mysqld_safe
[[email protected]]#
[[email protected]]#killallmysqld
mysqld:noprocesskilled

# 确定mysql已经停止服务


[[email protected]]#lsof-i:3306
[[email protected]]#

# 重新启动mysql服务


[[email protected]]#/etc/init.d/mysqld
startStartingMySQL..SUCCESS!
[[email protected]]#

# 检查端口


[[email protected]]#lsof-i:3306
COMMANDPIDUSERFDTYPEDEVICESIZE/OFFNODENAME
mysqld2872mysql10uIPv4235290t0TCP*:mysql(LISTEN)
[[email protected]]#

# 配置开机自启动mysql,也可以放在rc.local里


[[email protected]]#chkconfigmysqldon
[[email protected]upport-files]#
[[email protected]]#chkconfig--listmysqld
mysqld0:off1:off2:on3:on4:on5:on6:off
[[email protected]]#

# 再次登录mysql


[[email protected]]#mysql
WelcometotheMySQLmonitor.Commandsendwith;or/g...
mysql>

10、配置mysql登录密码


# 初始化时显示的设置密码和修改密码语句


/application/mysql/bin/mysqladmin-urootpassword‘new-password‘
/application/mysql/bin/mysqladmin-uroot-hdb01password‘new-password‘

# 设置密码


[[email protected]]#mysqladmin-urootpassword123456
[[email protected]]#

# 不用密码登录报错


[[email protected]]#mysql
ERROR1045(28000):Accessdeniedforuser‘root‘@‘localhost‘(usingpassword:NO)
[[email protected]]#

# 使用用户名和密码登录mysql


[[email protected]]#mysql-uroot-p123456

# 如果有密码,修改现有的密码


[[email protected]~]#mysqladmin-uroot-p123456password12345678

# 为了安全起见,登录采用如下方式


[[email protected]]#mysql-uroot-p
Enterpassword:
WelcometotheMySQLmonitor.Commandsendwith;or/g.YourMySQLconnectionidis5
mysql>

11、安全优化mysql步骤


1)修改root密码:


# 设置密码


[[email protected]]#mysqladmin-urootpassword123456
[[email protected]]#

# 如果有密码,修改现有的密码


[[email protected]~]#mysqladmin-uroot-p123456password12345678

2)删除test库:


mysql>showdatabases;
+--------------------+
|Database|
+--------------------+
|information_schema|#mysql数据库必备的库,自动维护
|mysql|#创建用户等数据会存放在这里
|performance_schema|#mysql数据库必须,自动维护
|test|#可以删除
+--------------------+
4rowsinset(0.00sec)
mysql>#
删除test库
mysql>dropdatabasetest;
QueryOK,0rowsaffected(0.02sec)
mysql>showdatabases;
+--------------------+
|Database|
+--------------------+
|information_schema|
|mysql|
|performance_schema|
+--------------------+
3rowsinset(0.00sec)
mysql>

3)删除无用的用户,删除用户需要主机,大写无法删除,特殊字符无法删除,此时需要使用特殊的SQL语句删除


(delete from mysql.user where user=’root’ andhost=’A用户’):


# 查询当前数据库里的用户


# 下面的显示里,root重复,在mysql里user +host确定一个唯一的用户


# root localhost和root db01不是一个用户


mysql>selectuser,hostfrommysql.user;
+------+------------+
|user|host|
+------+------------+
|root|127.0.0.1|
|root|::1|
||localhost|
|root|localhost|
||db01||root|db01|+------+------------+6rowsinset(0.00sec)mysql>

# 删除无用的用户


mysql>dropuser""@localhost;
QueryOK,0rowsaffected(0.00sec)
mysql>selectuser,hostfrommysql.user;
+------+------------+
|user|host|
+------+------------+
|root|127.0.0.1|
|root|::1|#::1表示IPV6的意思,这个用户无用,可以删除
|root|localhost|
||web-lnmp02|
|root|web-lnmp02|
+------+------------+
5rowsinset(0.00sec)

# 有时候,使用双引号””会报错,所以使用单引号’’会好些


mysql>dropuser""@web-lnmp02;
ERROR1064(42000):YouhaveanerrorinyourSQLsyntax;checkthemanualthatcorrespondstoyourMySQLserverversionfortherightsyntaxtousenear‘-lnmp02‘atline1
mysql>
mysql>
mysql>dropuser‘‘@‘web-lnmp02‘;
QueryOK,0rowsaffected(0.00sec)
mysql>
mysql>dropuser‘root‘@‘web-lnmp02‘;
QueryOK,0rowsaffected(0.00sec)
mysql>
mysql>dropuser‘root‘@‘::1‘;
QueryOK,0rowsaffected(0.00sec)
mysql>

# 删除用户后,最终检查,保留如下用户


mysql>selectuser,hostfrommysql.user;
+------+-----------+
|user|host|
+------+-----------+
|root|127.0.0.1|
|root|localhost|
+------+-----------+
2rowsinset(0.00sec)
mysql>

# 如果错把root localhost用户删除,可以通过命令创建出来


mysql>grantallon*.*to‘root’@localhostidentifiedby‘123456’withgrantoption;

# 刷新mysql系统权限相关表


mysql>flushprivileges;

12、mysql简单应用命令总结


1)Linux查看命令帮助使用man,内置命令使用help;在mysql中,使用help查看mysql的命令帮助:


mysql>helpdrop;
Manyhelpitemsforyourrequestexist.
Tomakeamorespecificrequest,pleasetype‘help‘,
whereisoneofthefollowing
topics:
ALTERTABLE
ALTERTABLESPACE
DEALLOCATEPREPARE
DROPDATABASE
DROPEVENT
DROPFUNCTION
DROPFUNCTIONUDF
DROPINDEX
DROPLOGFILEGROUP
DROPPROCEDURE
DROPSERVER
DROPTABLE
DROPTABLESPACE
DROPTRIGGER
DROPUSER
DROPVIEW
mysql>helpdropuser;
Name:‘DROPUSER‘
Description:
Syntax:
DROPUSERuser[,user]...
TheDROPUSERstatementremovesoneormoreMySQLaccountsandtheir
privileges.Itremovesprivilegerowsfortheaccountfromallgrant
tables.Tousethisstatement,youmusthavetheglobalCREATEUSER
privilegeortheDELETEprivilegeforthemysqldatabase.Eachaccount
nameusestheformatdescribedin
http://dev.mysql.com/doc/refman/5.5/en/account-names.html.Forexample:
#帮助里的例子
DROPUSER‘jeffrey‘@‘localhost‘;
Ifyouspecifyonlytheusernamepartoftheaccountname,ahostname
partof‘%‘isused.
URL:http://dev.mysql.com/doc/refman/5.5/en/drop-user.htmlmysql>

2)检查命令


mysql>showdatabases;#显示所有库
mysql>usemysql;#切换到mysql库
mysql>showtables;#显示当前库中所有表
mysql>selectuser,hostfrommysql.user;#查看用户列表
mysql>selectuser();#查看当前用户
mysql>selectdatabase();#查看当前所在库
mysql>dropdatabase库名;#删除数据库
mysql>dropuser’用户’@’主机’#删除用户
#删除用户
mysql>deletefrommysql.userwhereuser=”root”andhost=“A用户”

本文出自 “Linuxgao” 博客,请务必保留此出处http://linuxgao.blog.51cto.com/11934904/1931007


mysql-5.5.49版本二进制安装


标签:mysql-5.5.49二进制快速安装


原文:http://linuxgao.blog.51cto.com/11934904/1931007

相关阅读:
Top