Linux系统版本Centos7.5,使用yum进行mysql安装,但前提是Linux能连接外网。
1、mysql下载和安装
yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
yum install mysql-community-server
如果出现让你选择y/n的,基本默认选择y即可。
2、mysql服务启动
systemctl enable mysqld
systemctl start mysqld
3、查看mysql服务状态,我一般会使用以下两种方式之一进行查看:
systemctl status mysqld
如图,出现类似下方的结果,说明mysql服务已启动。
也可以使用查看进程的方式,查看mysql是否运行
ps -ef | grep mysqld
4、查看root用户的临时密码
grep 'temporary password' /var/log/mysqld.log
5、登录mysql服务,密码输入刚才获取的临时密码
mysql -h localhost -u root -p
6、修改密码
set password for root@localhost='xxxxxxx';
7、新建个数据库,创建个表试试
create database learn;
use learn;
create table student(stu_id int auto_increment primary key,stu_name varchar(100));
insert into student(name) values('tester1');
select * from student;
8、输入exit退出mysql命令环境
9、查看mysql的安装路径:which mysqld
10、查看mysql配置文件my.ini的内容,如查看mysql数据的存储位置
1)cat /etc/my.cnf
2)或者直接cat /etc/my.cnf | grep datadir
11、mysql服务关闭或重启
systemctl stop mysqld
systemctl restart mysqld