CentOS7安装MySQL
1.在安装前需要先去官网下载 Yum 资源包,下载地址为:https://dev.mysql.com/downloads/repo/yum/
wget http://repo.mysql.com/mysql80-community-release-el7-4.noarch.rpm
rpm -ivh mysql80-community-release-el7-4.noarch.rpm
yum update
yum install mysql-server
2.权限设置:
chown -R 777 /var/lib/mysql
3.初始化 MySQL:
mysqld --initialize
4启动 MySQL:
systemctl start mysqld
5查看 MySQL 运行状态:
systemctl status mysqld
6设置密码:
systemctl stop mysqld
修改配置文件:vim /etc/my.cnf
在[mysqld]下面增加:skip-grant-tables
7.登录设置用户和密码:(这一步做不做没什么关系,反正我做了感觉没用)
mysql -uroot -p
输入密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '******';
①use mysql;
update user set authentication_string='********' where user='root'; # 修改密码
或者应该也可以这样改:
②systemctl start mysqld
mysqladmin flush-privileges password '******'
查看当前用户信息:
select host,user from user;
FLUSH privileges; # 刷新mysql相关系统权限表
quit;
进入配置文件 vim /etc/my.cnf 将这行注释 skip-grant-tables 前面加#即可注释
8.创建数据库和要用的表
重新启动mysql,输入刚才设置的密码进入mysql:
systemctl stop mysqld
systemctl start mysqld
mysql -uroot -p
输入密码
CREATE DATABASE scheduling character set utf8mb4; # 创建数据库
USE scheduling; # 进入创建的数据库
用户表:
MariaDB [scheduling]> CREATE TABLE user(
id int not null auto_increment,
username varchar(20),
openid varchar(100),
avatar varchar(500),
workType int,
workTypeS int,
institutions int,
workplace varchar(100),
role int,
position varchar(100),
handoverId int,
handoverName varchar(100),
handoverPos varchar(100),
handoverIdS int,
handoverNameS varchar(100),
handoverPosS varchar(100),
primary key(id)
);
MariaDB [scheduling]> SHOW TABLES;
MariaDB [scheduling]> DESC user; # 查看表结构
机构表:
CREATE TABLE institution(
id int not null auto_increment,
organizationName varchar(100),
primary key(id)
);
ALTER TABLE scheduling.institution ADD UNIQUE (organizationName);