Note: The following operations are performed under Windows
Download: https://dev.mysql.com/downloads/mysql/
1. official website to download
2, for different operating systems to download different versions
3. Extract
mysqld --initialize-insecure
4. Add the environment variable
5. Initialize
mysqld --initialize-insecure
6. Start sql service
mysqld # Start MySQL service
can also be made into MySQL Windows Service Note: - before install, you must start with the absolute path to the command MySQL # make MySQL Windows service, execute this command in Terminal: "c: \ MySQL-5.6.40 -winx64 \ bin \ mysqld "--install # remove MySQL Windows service, execute this command in terminal: " c: \ MySQL-5.6.40-Winx64 \ bin \ mysqld "--remove after registering as a service at a later time when you start and shut down the MySQL service, just execute the following command: # start MySQL service NET start MySQL # shut down MySQL service net stop mysql
7. Start the mysql client and connect mysql server (cmd to open a new window)
MySQL - U root - the p-# connect to the MySQL server
8. Set password
- Open the terminal input mysql
- Function of the input provided by mysql: select user (); # to view the current account logs
- 当前登录的默认账号为ODBC@localhost,如果想切到root账号登录 执行命令:mysql -uroot -p
- 设置管理员root账号密码为123
C:\Users\mjj>mysqladmin -uroot -p password "123" #设置初始密码 由于原密码为空,因此-p可以不用 Mysql版本的不同,可能执行这句指令不起作用,请使用update mysql.user set authentication_string =password('') where User='root';
9.忘记密码(破解密码)
- 以管理员身份打开cmd
- 停掉mysql服务端
C:\WINDOWS\system32>net stop mysql MySQL 服务正在停止. MySQL 服务已成功停止。
- 执行如下命令跳过授权表
#跳过授权表 C:\WINDOWS\system32>mysqld --skip-grant-tables 2018-06-09 17:12:38 0 [Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path. 2018-06-09 17:12:38 0 [Note] mysqld (mysqld 5.6.40) starting as process 6052 ...4.
- 现在可以不需要密码直接登录mysql
mysql -uroot -p
- 现在可以任意的更改密码,执行如下命令
update mysql.user set authentication_string =password('') where User='root';
- 刷新权限
flush privileges;
- 退出mysql
- 让用户去加载权限,以管理员身份进入cmd,查看当前mysql进程
tasklist |findstr mysql #查看当前mysql的进程
- 杀死当前的进程,执行如下命令
taskkill /F /PID 进程ID # 杀死当前的进程pid
- 重启mysql服务
10.统一字符编码
- 进入mysql客户端,执行\s
- 为了统一字符编码,请执行如下操作:
-
在C:\mysql-5.6.40-winx64文件下创建my.ini文件
- 在my.ini文件中写入一下代码
[mysqld] # 设置mysql的安装目录 **后面的路径一定是安装sql的目录(自己电脑的)** basedir=C:\mysql-5.7.22-winx64\mysql-5.7.22-winx64 # 设置mysql数据库的数据的存放目录,必须是data datadir=C:\mysql-5.7.22-winx64\mysql-5.7.22-winx64\data sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES # mysql端口 port=3306 # 字符集 [mysqld] character-set-server=utf8 collation-server=utf8_general_ci [client] default-character-set=utf8 [mysql] default-character-set=utf8
- 重启mysql
-