Linux安装MySQL(5.7.24)

前奏

一、使用命令查看是否已安装MySQL

yum list installed | grep mysql

二、如果有安装MySQL,请先卸载

yum –y remove mysql-libs.X86_64
或
yum erase mysql-libs.x86_64

在线安装

一、安装客户端

yum install mysql

二、安装服务端

yum install mysql-server

三、开启服务

service mysqld start 

 四、验证是否开启服务

service mysqld status

五、root进入Mysql;

mysql -u root(回车,密码为空,回车),进入到mysql命令行页面

六、创建用户

create user 'hive' identified by '123456';

 手动安装

一、下载mysql二进制文件mysql-5.7.24-el7-x86_64.tar.gz

二、解压

tar -zxvf mysql-5.7.24-el7-x86_64.tar.gz

三、改名

mv mysql-5.7.24-el7-x86_64.tar.gz mysql

 四、建数据库存放文件夹

mkdir -pv /home/sweeney/data/mysqldb/3306/{logs,run,data}
touch /home/sweeney/data/mysqldb/3306/run/mysqld.pid
touch /home/sweeney/data/mysqldb/3306/logs/mysql-error.log

五、修改配置文件(/home/sweeney/soft/mysql/my.cnf)

[client]
port=3306
socket=/home/sweeney/data/mysqldb/3306/mysql.sock
default_character_set=utf8

[mysqld]
user=sweeney
port=3306
socket=/home/sweeney/data/mysqldb/3306/mysql.sock
basedir=/home/sweeney/soft/mysql
datadir=/home/sweeney/data/mysqldb/3306/data
pid-file=/home/sweeney/data/mysqldb/3306/run/mysqld.pid
log-error=/home/sweeney/data/mysqldb/3306/logs/mysql-error.log
character_set_server=utf8

[mysql]
socket=/home/sweeney/data/mysqldb/3306/mysql.sock

[mysqldump]
socket=/home/sweeney/data/mysqldb/3306/mysql.sock

[mysqladmin]
socket=/home/sweeney/data/mysqldb/3306/mysql.sock

六、初始化mysql安装

cd /home/sweeney/soft/mysql
sudo ./bin/mysqld --defaults-file=/home/sweeney/soft/mysql/my.cnf --initialize-insecure --user=sweeney --datadir=/home/sweeney/data/mysqldb/3306/data

七、修改./support-files/mysql.server

basedir=/home/sweeney/soft/mysql
datadir=/home/sweeney/data

八、把启动脚本放到开机初始化目录

cd /home/sweeney/soft/mysql
sudo cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld

九、添加开机启动mysql服务

sudo chkconfig --add mysqld
sudo chkconfig mysqld on
chkconfig --list mysqld

十、启动mysql服务

service mysqld start
或
~/soft/mysql/support-files/mysql.server start

十一、查看mysql服务是否启动

ps -ef|grep mysql

十二、配置环境变量(一定要export)

export MYSQL_HOME=/home/sweeney/soft/mysql
export PATH=$PATH:$MYSQL_HOME/bin

十三、修改root的密码

mysql -u root -p
set password for 'root'@'localhost'=password('123456');

十四、配置Mysql服务远程可访问

使用如下命令,授权root 用户远程连接服务器:
grant all privileges on *.* to 'root'@'%' identified by "123456" with grant option;
flush privileges;
exit;

 

你可能感兴趣的:(Linux)