SQL基本
配置
官网下载免安装的SQL压缩包,之后把bin目录添加到环境变量里面
新建my.ini
文件,填入下面语句
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
#skip-grant-tables
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
basedir ="PATH" # 设置mysql的安装目录
datadir ="PATH\data" # 设置mysql数据库的数据的存放目录,必须是data,或者是//xxx/data
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#服务端的编码方式
character-set-server=utf8mb4
[client]
#客户端编码方式,最好和服务端保存一致
loose-default-character-set=utf8mb4
[WinMySQLadmin]
Server = "PATH\mysqld.exe"
以管理员模式启动cmd
指令窗口然后输入mysqld –install
再输入 mysqld --initialize -insecure --user=mysql
初始化数据文件
然后进入SQL用mysql -u root -p
注意-p后面不用加空格
更改root密码update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost';
更改权限flush privileges;
启动SQL服务
net stop mysql
关闭sql服务
net start mysql
打开MySQL命令窗口
- 在DOS命令行窗口进入 安装目录
\mysql\bin
- 可设置环境变量,设置了环境变量,可以在任意目录打开!
连接数据库语句 : mysql -h
服务器主机地址 -u
用户名 -p
用户密码
注意 : -p
后面不能加空格,否则会被当做密码的内容,导致登录失败 !
几个基本的数据库操作命令 :
update user set password=password('123456')where user='root'; 修改密码
flush privileges; 刷新数据库
show databases; 显示所有数据库
use dbname;打开某个数据库
show tables; 显示数据库mysql中所有的表
describe user; 显示表mysql数据库中user表的列信息
create database name; 创建数据库
use databasename; 选择数据库
exit; 退出Mysql
? 命令关键词 : 寻求帮助
-- 表示注释
docker run -itd --net=host -p 3306:3306 --restart always
-e MYSQL_ROOT_PASSWORD=xxx \
--name my-mysql \
mysql:5.7 \
--character-set-server=utf8mb4
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)