1. MySQL基本使用
1.1 数据库简介
- Mysql: 关系型数据库,做网站
- redis:当作缓存
- mongodb:非关系型数据库,做爬虫
- SQL语句:
- DQL:数据查询语言,用于对数据进行查询,如select
- DML:数据操作语言,对数据进行增加、修改、删除,如insert、update、delete
- TPL:事务处理语言,对事务进行处理,包括begin transaction、commit、rollback
- DCL:数据控制语言,进行授权与权限的回收,如grant、revoke
- DDL:数据定义语音,进行数据库、表的管理等,如create、drop
- CCL:指针控制语言,通过控制指针完成表的操作,如declare cursor
- MySQL安装
- 安装服务器段,输入:sudo apt-get install mysql-server (ubuntu里已经安装好了mysql服务器端,无须再安装,并且设置成了开机启动
- 服务器用于接收客户端的请求,执行sql语句,管理数据库
- 服务器端一般以服务方式管理,名称mysql
- 启动服务器: sudo service mysql start
- 查看进程中是否存在mysql服务: ps -aux |grep mysql
- 停止服务: sudo service mysql stop
- 重启服务: sudo service mysql restart
- 配置
- 配置文件目录为:/etc/mysql/mysql.cnf
- 进入conf.d目录,打开mysql.cnf,发现没有配置
- 进入mysql.conf.d目录,打开mysql.cnf,可以看到配置项
- 主配置项如下:
- 配置文件目录为:/etc/mysql/mysql.cnf
# # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. bind-address = 127.0.0.1 # # * Fine Tuning # key_buffer_size = 16M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 # This replaces the startup script and checks MyISAM tables if needed # the first time they are touched myisam-recover-options = BACKUP #max_connections = 100 #table_open_cache = 64 #thread_concurrency = 10 # # * Query Cache Configuration # query_cache_limit = 1M query_cache_size = 16M # # * Logging and Replication # # Both location gets rotated by the cronjob. # Be aware that this log type is a performance killer. # As of 5.1 you can enable the log at runtime! #general_log_file = /var/log/mysql/mysql.log #general_log = 1 # # Error log - should be very few entries. # log_error = /var/log/mysql/error.log
- 客户端
- 安装:sudo apt-get install mysql-client
- 帮助:mysql --help
- 最基本的连接命令如下:sudo mysql -u root -pmysql
1.2 数据完整性
1.3 命令行脚本
1.4 数据库设计
2. MySQL查询
3. MySQL和Python交互
4. MySQL高级