首页 » MySQL » CentOS7服务器安装mysql

CentOS7服务器安装mysql

原文 http://blog.csdn.net/zimou5581/article/details/78091090

2017-09-26 12:21:00阅读(370)

下载安装

下载64位安装包,安装目录为/usr/mysql

wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz


解压

tar -zxf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz


重命名解压文件夹并删除安装包

mv mysql-5.6.33-linux-glibc2.5-x86_64 mysql

rm -rf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz


添加用户组

groupadd mysql

添加用户mysql 到用户组mysql

useradd -g mysql mysql


安装

cd /usr/mysql/

mkdir ./data/mysql

chown -R mysql:mysql /usr/mysql/

yum -y install autoconf 或者 yum -yinstall perl perl-devel

yum install libaio* 或者 yum -yinstall libaio-devel

./scripts/mysql_install_db --user=mysql--datadir=/usr/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


修改启动脚本

vim /etc/init.d/mysqld

basedir=/usr/mysql/

datadir=/usr/mysql/data/mysql


启动服务

service mysqld start

测试连接

./mysql/bin/mysql -uroot


基本设置

添加环境变量

vim /etc/profile

exportPATH=$PATH:/usr/mysql/bin

source /etc/profile


设置开启启动

systemctl is-enabled mysqld

systemctl enable mysqld

systemctl stop mysqld

systemctl start mysqld

systemctl status mysqld


启动mysql

service mysqld start

关闭mysql

service mysqld stop

查看运行状态

service mysqld status


修改root密码,默认为空

mysql -uroot -p

mysql>use mysql;

mysql> update user setpassword=passworD("test") where user='root';

mysql> flush privileges;

mysql> exit; 


删除匿名用户(也可以直接在数据库图形界面找到user表删除user为空的记录)

DELETE FROM mysql.user WHERE USER='';

DELETE FROM USER WHERE USER IS NULL;

FLUSH PRIVILEGES;


开启远程访问权限

mysql>use mysql;

mysql> GRANT ALL PRIVILEGES ON *.* TO'youruser'@'%'IDENTIFIED BY 'yourpwd' WITH GRANT OPTION;

mysql> flush privileges;

mysql>exit; 


ps:

防火墙请手动关闭,或设置防火墙对3306端口放行

服务器要配置入方向,端口3306

最新发布

CentOS专题

关于本站

5ibc.net旗下博客站精品博文小部分原创、大部分从互联网收集整理。尊重作者版权、传播精品博文,让更多编程爱好者知晓!

小提示

按 Ctrl+D 键,
把本文加入收藏夹