CherieLi Student

mysql 教程

2020-07-29
CherieLi

http://www.runoob.com/mysql/mysql-tutorial.html

安装部署

https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/
或者:下载网址:https://downloads.mysql.com/archives/community/
yum remove mariadb-libs
sudo rpm -ivh mysql-community-common-5.7.25-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-libs-5.7.25-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-client-5.7.25-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-server-5.7.25-1.el7.x86_64.rpm
启动:
service mysqld start
状态确认:
service mysqld status
跳过密码验证方式重新启动MySQL服务,并允许任意连接:
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
service mysqld  restart
mysql -u root -p
输入password为空格

\G 终止符可以将查询结果以垂直格式显示

初始化

/home/mysql/bin/mysqld –defaults-file=/home/my.cnf –initialize

初始化密码见:error.log


mysqlpassword=$(cat /home/data/error.log |grep "root@localhost" |awk -F ':' '{print $5}'|awk '{gsub(/^\s+|\s+$/, "");print}')

echo $mysqlpassword

启动

/home/mysql/bin/mysqld –defaults-file=/home/my.cnf&

/home/mysql/bin/mysqld –defaults-file=/home/my.cnf –initialize-insecure

/home/mysql/bin/mysqladmin -uroot password -S /tmp/mysql.sock

/home/mysql/bin/mysql -uroot -phello -S /tmp/mysql.sock

修改密码1

/home/mysql/bin/mysql –connect-expired-password -uroot -p${mysqlpassword} -S /tmp/mysql.sock « EOF

set password for root@localhost = password(‘hello’);

commit;

flush privileges;

EOF

修改密码2

The MySQL server is running with the –skip-grant-tables option so it cannot execute this statement

flush privileges; alter user ‘root’@’localhost’ identified by ‘test123’;

正常关闭

/home/mysql/bin/mysqladmin -uroot -phello -S /tmp/mysql.sock shutdown

官方文档

https://dev.mysql.com/doc/refman/5.7/en/information-schema-introduction.html
https://dev.mysql.com/doc/refman/5.7/en/enum.html https://dev.mysql.com/doc/refman/5.7/en/set.html

git clone https://gitee.com/mirrors/mysql-server.git mysql源码

工具

MyDumper: https://github.com/mydumper/mydumper 逻辑备份工具,负责导出MySQL数据库的一致备份,生成的文件全是query语句
myloader: 与 mydumper 工具配合使用的多线程备份恢复工具

schema

创建一个schema就是:
create user [***] no authentication
alter user [***] account locak
grant select on ... to [...]
grant select on ... to public

mysql的user和schema是分开的;
在mysql模式下建的user不能作为schema使用。你需要use database或者alter session set current_schema,把当前的schema切换成通过create database或者create schema创建出来的schema。

oracle的schema = user;

数据类型

mysql> ? data types;   支持的所有数据类型
mysql> ? ENUM;      ENUM类型的具体介绍
mysql> ? show;      show语法

varchar 64KB
https://blog.csdn.net/qq_34115899/article/details/117524328

sql改写

with cte1 as()
select from cte1

权限

权限: read与select权限的区别: select = read + select for update
https://blog.csdn.net/youziguo/article/details/142768272
user 表:存储用户的全局权限。
db 表:存储数据库级别的权限。
tables_priv 表:存储表级别的权限。
columns_priv 表:存储列级别的权限。
procs_priv 表:存储存储过程和函数的权限。

学习参考文档

https://c.biancheng.net/view/2426.html
https://dev.mysql.com/downloads/
https://dev.mysql.com/doc/
https://bugs.mysql.com/
https://syxdevcode.github.io/2021/01/13/MySQL-GRANT%E5%91%BD%E4%BB%A4-%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83/
https://www.cnblogs.com/HealerJean/p/11829991.html
https://blog.csdn.net/qq_43079001/article/details/134175890
https://zhuanlan.zhihu.com/p/607369709
https://segmentfault.com/a/1190000009540449 null与空值判断
https://geek-docs.com/sql/sql-ask-answer/738_sql_differences_between_foreign_key_and_constraint_foreign_key.html
“foreign key”和“constraint foreign key”之间的差异
https://github.com/mysql/mysql-server/blob/5.7/scripts/mysql_system_tables.sql 系统表


Comments

Content