欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

CentOS7服务器安装mysql数据库详细教程

程序员文章站 2022-09-28 14:54:52
下载安装 下载64位安装包,安装目录为/usr/mysql wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5...

下载安装

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

wget https://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/local/mysql//bin

source /etc/profile

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;

开启远程访问权限

mysql>use mysql;

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

mysql> flush privileges;

mysql>exit;

ps:

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

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