在官网下载mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz,上传到服务器,或者直接在服务器用wget 直接下载下来,安装步骤如下:
1.解压安装包
命令:tar zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
2.转移安装包,将安装包复制到/usr/local/mysql处
命令:cp -r mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql
注意目标目录最后不能添加/
3.添加mysql组和添加mysql的用户
命令:
groupadd mysql
useradd -r -g mysql mysql
4.跳转到/usr/local/mysql
命令:cd /usr/local/mysql/
5.将mysql安装目录下的所有文件的拥有者修改为mysql用户
命令:chown -R mysql:mysql ./
6.安装mysql
命令:./scripts/mysql_install_db --user=mysql
可能出现的问题:
(1)出现问题A
a.报错信息:FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper
b.导致原因: 没有安装perl module(autoconf)
c.解决方案:安装autoconf
命令:yum installautoconf
(该命令视linux系统而定,在centos下为yum install,在unbuntu下为apt-get install)
(2)问题2
a.报错信息:Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
b.导致原因:没有安装libaio-devel
c.解决方案:安装libaio-devel
命令:yum install libaio-devel
(该命令视linux系统而定,在centos下为yum install,在unbuntu下为apt-get install)
7.将当前目录及其文件全部修改为root用户
命令:chown -R root:root ./
8.将安装包下的data目录的拥有者修改为mysql用户
命令:chown -R mysql:mysql data
9.添加开机自启动
命令:cp support-files/mysql.server /etc/init.d/mysql
10.将刚添加的自启动程序添加可执行权限
命令:chmod +x /etc/init.d/mysql
11.添加mysql服务
命令:chkconfig --add mysql
12.检测服务是否可用
命令:chkconfig --list
若mysql下的3,4,5均为on为成功,网上说,若不成功可填入:chkconfig --level 345 mysql on
(暂未尝试过)
13.启动mysql
命令:service mysql start
可能出现的错误:(若出现问题,需要进入14步骤修改密码)
(1)问题一
a.问题显示
Starting MySQL.touch: cannot touch '/var/log/mariadb/mariadb.log': No such file or directory
chmod: cannot access '/var/log/mariadb/mariadb.log': No such file or directory
touch: cannot touch '/var/log/mariadb/mariadb.log': No such file or directory
chown: cannot access '/var/log/mariadb/mariadb.log': No such file or directory
/usr/local/mysql/bin/mysqld_safe: line 129: /var/log/mariadb/mariadb.log: No such file or directory
/usr/local/mysql/bin/mysqld_safe: line 166: /var/log/mariadb/mariadb.log: No such file or directory
touch: cannot touch '/var/log/mariadb/mariadb.log': No such file or directory
chown: cannot access '/var/log/mariadb/mariadb.log': No such file or directory
chmod: cannot access '/var/log/mariadb/mariadb.log': No such file or directory
/usr/local/mysql/bin/mysqld_safe: line 129: /var/log/mariadb/mariadb.log: No such file or directory
The server quit without updating PID file (/var/lib/mysql/i[FAILED]3vu81gmebyu2tZ.pid).
b.产生原因:log目录没有创建/var/log/mariadb/
c.解决方案:创建log目录文件夹
命令:mkdir /var/log/mariadb
14.修改密码:
命令:./bin/mysqladmin -u root password '这里填写你的密码'
可能出现问题:
(1)问题一
a.错误信息:
./bin/mysqladmin: connect to server at 'localhost' failed
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!
b.解决方案
首先,关闭mysql服务
其次,修改配置文件(5.6.33是my.cnf,部分为my.conf),在配置文件处的[client]下添加socket=/var/lib/mysql/mysql.sock,如图所示
最后,重新启动mysql,
命令:/usr/local/mysql/bin/mysqld_safe& service mysql start
14.无法使用14直接修改密码的继续这一步骤
a.进入刚刚安装目录下的bin
命令:cd /usr/local/mysql/bin
b.进入mysql
命令:./mysql -u root -p
密码为空
c.在mysql控制台下:
use mysql;
update user set password=password("你的密码") where user = 'root' and host = 'localhost';
flush privileges;
网友评论