centos7安装mysql5.7

本例以root权限安装mysql数据库,mysql-5.1.37-linux-x86_64-glibc23.tar.gz安装包在/root/Nagios/ 目录下(根据实际情况)。

ü     在mysql-5.1.37-linux-x86_64-glibc23.tar.gz安装包所在目录,解压软件包

cd /root/Nagios/

tar -zvxf mysql-5.1.37-linux-x86_64-glibc23.tar.gz

ü     将解压的mysql文件夹,移到/usr/local/目录下

mv mysql-5.1.37-linux-x86_64-glibc23 /usr/local/mysql

ü     将mysql配置文件拷贝到/etc/目录下,并改名my.cnf

cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf

ü 添加mysql用户及用户组,用来运行mysql数据库

groupadd mysql

useradd -g mysql mysql

ü 修改mysql目录权限

// 设定root能访问/usr/local/mysql

chown -R root /usr/local/mysql                                                                                  

// 设定mysql组能访问/usr/local/mysql

chgrp -R mysql /usr/local/mysql                                                                                 

// 设定mysql用户能够访问/var/lib/mysql

chown -R mysql /usr/local/mysql/data

ü 在mysql解压目录下,生成mysql系统数据库,本例安装在/usr/local/mysql目录下

cd /usr/local/mysql                                                                                                   

./scripts/mysql_install_db --user=mysql&                                                                    

ü 以mysql用户启动mysql服务

/usr/local/mysql/bin/mysqld_safe -user=mysql&

ü 修改mysql的root密码,密码假定为:123456

/usr/local/mysql/bin/mysqladmin -u root password 123456

ü 进入MYSQL安装路径下的bin目录,以root用户登录mysql:

cd /usr/local/mysql/bin                                                                                       

./mysql -u root -p                                                                                                    

输入密码:123456

ü 开启 mysql 本地和远程访问

grant all on *.* to root@本机IP

grant all privileges on *.* to root @"%" identified by "123456";

flush privileges;


说明:

grant all privileges on *.* tousername@"%" identified by "password";

all指定相关操作

*.*说明数据库和表名

username表示用户名

%这里是Host名称,允许所有的就用%

Password表示密码

  设置MySQL服务及命令

拷贝mysql安装目录下bin/目录中的文件到/usr/bin目录,使mysq等命令可以在任一路径执行:

cp /usr/local/mysql/bin /usr/bin

设置mysql启动命令,打开/usr/local/mysql/support-files/mysql.server文件,将以下内容:

$bindir/safe_mysqld --datadir=$datadir --pid-file=$pid_file &

改为:

$bindir/safe_mysqld --datadir=$datadir --user=root --pid-file=$pid_file &

       拷贝到/etc/init.d目录,并赋可执行权限

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

chmod +x /etc/init.d/mysql

       以root用户调用以下命令启动mysql服务

service mysql start

       设置mysql自启动

在文件/etc/rc.d/rc.local中添加

service mysql start

数据库初始化

       登陆MySQL,并创建数据库ccms02及表

ü 登陆MySQL

cd /usr/local/mysql/bin                                                                                       

./mysql -u root -p

ü 创建名称为test02的数据库

create database test02 default character set utf8;

ü 退出MySQL,导入建表脚本test02.sql

/usr/local/mysql/bin/mysql -u root -p -D 

 test02< /home/cloudsync/db/test02.sql

ü 导入完成后,重新登陆MySQL,依次执行以下语句,可以查看建表结果

ü ./mysql -u root –p

use test02;

show tables;

你可能感兴趣的:(centos7安装mysql5.7)