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

下载安装

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

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 -u root

基本设置

添加环境变量

vim /etc/profile

export MYSQLPATH=$PATH:/usr/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 -u root -p

mysql>use mysql;

mysql> UPDATE user SET Password = PASSWORD('newpassword') WHERE user = 'root';

mysql> flush privileges;

mysql> exit;

登录MySQL路径/usr/mysql/bin/

# ./mysql -u root -p

开启远程访问权限

mysql>use mysql;

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

mysql> flush privileges;

mysql>exit;

ps:

防火墙请手动关闭,或设置防火墙对3306端口放行
云服务器要配置入方向,端口3306

注:若出现错误查看错误日志在解决错误(mysql>data>mysql>xxx.err,具体路径可能不是相同的,只要找到xxx.err文件就可以了)指令: vi xxx.err 来查看具体错误

你可能感兴趣的:(实战开发)