1、下载
下载地址:http://dev.mysql.com/downloads/mysql/5.6.html#downloads
下载版本:我这里选择的5.6.33,通用版,linux下64位
也可以直接复制64位的下载地址,通过命令下载:wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
下载地址: https://pan.baidu.com/s/1i4VW6NF 密码: n2k6
指令 ps -ef|grep mysql
- root 17659 1 0 2011 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid
- mysql 17719 17659 0 2011 ? 03:14:57 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sock
usr/bin/mysql 是指:mysql的运行路径
var/lib/mysql 是指:mysql数据库文件的存放路径
usr/lib/mysql 是指:mysql的安装路径
本地上传文件到服务器:scp atlassian-jira-software-7.13.0-x64.bin root@192.168.198.141:/user
2、解压
1
2
3
4
|
#解压 tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64. tar .gz #复制解压后的mysql目录 mv mysql-5.6.28-linux-glibc2.5-x86_64 /usr/local/
|
3、添加用户组和用户
1
2
3
4
|
#添加用户组 groupadd mysql #添加用户mysql 到用户组mysql useradd -g mysql mysql |
4、安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
进入安装mysql目录: cd /usr/local mv mysql-5.6.28-linux-glibc2.5-x86_64 mysql
cd /usr/local/mysql
修改当前目录拥有者为mysql用户: chown -R mysql . chgrp -R mysql .
执行命令: scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/mysqldata/ [root@198-141 mysql]# scripts/mysql_install_db --user=mysql --ldata=/var/lib/mysql/ (MySQL初始化脚本mysql_install_db,其中--user为mysqld服务的运行用户 --basedir和--datadir则分别代表mysql的安装目录和数据存放目录 ) [root@db19320 mysql]# cp support-files/mysql.server /etc/init.d/mysql.server
#修改启动脚本 vi /etc/init .d /mysqld #修改项: basedir= /usr/local/mysql/ datadir= /usr/local/mysql/data/mysql #启动服务 service mysqld start #测试连接 . /mysql/bin/mysql -uroot #加入环境变量,编辑 /etc/profile,这样可以在任何地方用mysql命令了 export PATH=$PATH: /usr/local/mysql//bin <br> source /etc/profile 配置环境变量 vi /etc/profile
export PATH=....:/usr/local/mysql/bin #启动mysql service mysql start #关闭mysql service mysql stop #查看运行状态 service mysql status |
5、常见错误
(1)近日在启动mysql时,遇到一个问题,现记录一下
Starting MySQL. ERROR! The server quit without updating PID file (/var/lib/mysql/198-141.pid).
此问题的原因是没有进行初始化库,使用如下命令:
mysql_install_db --user=mysql --ldata=/var/lib/mysql/
(2)数据库连接时报错error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
查看/tmp文件夹的确没有mysql.sock文件,我们需要修改my.cnf文件
[root@localhost /]# vi /etc/my.cnf
socket = /tmp/mysql.sock,
保存后,执行连接测试
./mysql/bin/mysql -uroot
(3) sqlyog连接时,报1130错误,是由于没有给远程连接的用户权限问题
解决1:更改 ‘mysql’数据库‘user’表‘host’项,从‘localhost’改成‘%’。
use mysql; select 'host' from user where user='root'; update user set host = '%' where user ='root'; flush privileges;
解决2:直接授权
GRANT ALL PRIVILEGES ON *.* TO ‘root’@'%’ IDENTIFIED BY ‘youpassword’ WITH GRANT OPTION;
(4) 安装时的一些错误
-bash: ./scripts/mysql_install_db: /usr/bin/perl: bad interpreter: 没有那个文件或目录
解决: yum -y install perl perl-devel
Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决:yum -y install libaio-devel
(5)ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)解决方法?
#1.停止mysql数据库
/etc/init
.d
/mysql
stop
#2.执行如下命令
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
#3.使用root登录mysql数据库
mysql -u root mysql
.
/mysql/bin/mysql
-uroot
#4.更新root密码
mysql> UPDATE user SET Password=PASSWORD(
'newpassword'
) where USER=
'root'
;
#最新版MySQL请采用如下SQL:
mysql> UPDATE user SET authentication_string=PASSWORD(
'123456'
) where USER=
'root'
;
#5.刷新权限
mysql> FLUSH PRIVILEGES;
#6.退出mysql
mysql> quit
#7.重启mysql
/etc/init
.d
/mysql
restart
#8.使用root用户重新登录mysql
mysql -uroot -p
Enter password: 123456
(6)出现-bash: mysql: command not found的方法
原因:因为系统默认会查找/usr/bin下的命令,由于mysql没有在这个目录下,所以出现not found。因此需要做一个软连接到/usr/bin目录下。
执行命令: ln -s /usr/local/mysql/bin/mysql /usr/bin
其中/usr/local/mysql 为:mysql的安装路径