1、文档描述
该文档主要是提供如何在服务器上安装各种数据库的文档。
2、数据库编码
数据库编码为utfmb4
3、基本指令
查看linux 版本: cat /etc/redhat-release
操作系统位数: getconf LONG_BIT
4、下载mysql
mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
5、解压mysql
tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
6、新建my.cnf 文件
[client]
port=3306
socket=/home/mysql/mysql/mysql.sock
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
socket=/home/mysql/mysql/mysql.sock
[mysqld]
port=3306
basedir=/home/mysql/mysql
datadir=/home/mysql/mysql/data
pid-file=/home/mysql/mysql/mysql.pid
socket=/home/mysql/mysql/mysql.sock
log_error=/home/mysql/mysql/error.log
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
[mysqldump]
socket=/home/mysql/mysql/mysql.sock
[mysqladmin]
socket=/home/mysql/mysql/mysql.sock
6、配置环境变量
在.bash_profile 配置:
export MYSQL_HOME=/home/mysql/mysql
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH=$MYSQL_HOME/bin:$PATH
7、初始化目录
mysqld --defaults-file=/home/mysql/mysql/my.cnf --initialize --user=im --basedir=/home/mysql/mysql --datadir=/home/mysql/mysql/data
8、安全启动
mysqld_safe --defaults-file=/home/mysql/mysql/my.cnf --user=mysql &
9、关闭mysql
mysqladmin shutdown -uroot -p
10、首次登录
密码通过cat error.log | grep root@localhost
mysql -u root -p
原密码为:7yw12MN;VmVW ,修改为yourpassword
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY yourpassword
12、新建用户授权
新建数据库为test,登录mysql后在mysql命令行执行:
create user test identified by 'yourpassword';
grant all privileges on . to test@'%' identified by 'yourpassword';
flush privileges;
创建一个用户为test,同时授予该用于test 数据库的所有权限
创建数据库:
指令:create database datams;
指令:flush privileges;