Linux系统安装MySql数据库

1.检查环境(初次安装略过)
检查是否存在依赖 
rpm -qa|grep -i mysql

如果存在卸载 
rpm -ev <包的名字>
如果遇到依赖,无法删除,使用(不检查依赖,直接删除rpm包)
rpm -ev <包的名字> --nodeps

2.下载安装包上传至Linux服务器

3.解压安装包,更名并新建data目录
cd /usr/local
tar -xvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql
mkdir /usr/local/mysql/data

4.新建mysql用户、mysql用户组,并赋权
groupadd mysql
useradd mysql -g mysql
chown -R mysql.mysql /usr/local/mysql

5.数据库初始化,并修改配置文件
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
Tip:执行完后,备注root用户的初始密码 root@localhost: 4tciw8?ffvkW

vi /etc/my.cnf
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8

#表名忽略大小写
lower_case_table_names=1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

6.加环境变量
vi /etc/profile
Tip:在末尾加上 export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile

7.启动数据库(用刚才的备注密码)
mysql -u root -p
#修改root用户密码
SET PASSWORD = PASSWORD('root');
#给mysql用户赋权
grant all on *.* to mysql@'%' identified by 'mysql' with grant option; 
flush privileges;

#启动
service mysql start
#停止
service mysql stop
#重启
service mysql restart

你可能感兴趣的:(DataBase)