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
# 安装依赖
yum -y install perl perl-devel autoconf libaio
2、解压
1
2
3
4
|
#解压 tar -zxvf
mysql-5.6.33-linux-glibc2.5-x86_64. tar .gz #复制解压后的mysql目录
cp mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql -r
|
3、添加用户组和用户
|
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
|
cd /usr/local/mysql/ <br
data-filtered= "filtered" > mkdir . /data/mysql chown -R
mysql:mysql ./ . /scripts/mysql_install_db --user=mysql
--datadir= /usr/local/mysql/data/mysql cp support-files /mysql .server /etc/init .d /mysqld chmod 755 /etc/init .d /mysqld cp support-files /my-default .cnf /etc/my .cnf #修改启动脚本 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
data-filtered= "filtered" > source /etc/profile #启动mysql service
mysqld start #关闭mysql service
mysqld stop #查看运行状态 service
mysqld status |
5.1 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:直接授权
授权%所有电脑都可用root账户管理mysql所有数据库和表密码为youpassword
GRANT ALL PRIVILEGES ON *.* TO ‘root’@'%’ IDENTIFIED BY ‘youpassword’ WITH GRANT
6、进入安装mysql软件目录,修改目录拥有者为mysql用户
cd mysql/
chown -R mysql:mysql ./
7、安装数据库,此处可能出现错误。
./scripts/mysql_install_db --user=mysql
FATAL ERROR: please install the following Perl modules before executing scripts/mysql_install_db:
Data::Dumper
#解决方法:
yum install -y perl-Data-Dumper
8、修改当前目录拥有者为root用户
chown -R root:root ./
9、修改当前data目录拥有者为mysql用户
chown -R mysql:mysql data
============== 到此数据库安装完毕 =============
10、添加mysql服务开机自启动
添加开机启动,把启动脚本放到开机初始化目录。
cp support-files/mysql.server /etc/init.d/mysql # 赋予可执行权限 chmod +x /etc/init.d/mysql # 添加服务 chkconfig --add mysql # 显示服务列表 chkconfig --list
如果看到mysql的服务,并且3,4,5都是on的话则成功,如果是off,则执行
chkconfig --level 345 mysql on
11、启动mysql服务
#创建缺少的文件夹
mkdir /var/log/mariadb
service mysql start
权限控制
1、去除匿名用户
# 测试匿名用户登录
mysql -ux3
# 删除匿名用户,使用root用户登录数据库 delete from mysql.user where User='';
flush privileges;