前言
今天临时需要在办公环境安装个数据库,简单记录下安装过程及中间问题解决方案。
mysql安装过程
下载MySql
解压放在D:\Program Files下
配置
创建数据目录和配置文件
D:\Program Files\mysql-5.7.41-winx64\data\
D:\Program Files\mysql-5.7.41-winx64\my.ini
[mysql]
auto-rehash
default-character-set = utf8mb4
connect-timeout = 3
[mysqld]
skip-name-resolve
bind-address=0.0.0.0
port = 3306
# 设置mysql的安装目录
basedir=D:\Program Files\mysql-5.7.41-winx64
# 设置mysql数据库的数据的存放目录
datadir=D:\Program Files\mysql-5.7.41-winx64\data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine = INNODB # myisam 或 INNODB
#innodb_buffer_pool_size = 100M
lower_case_table_names=1
max_allowed_packet=16M
sql_mode='STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'
#skip-grant-tables # 放开次参数root免密码登录
启动
设置环境变量 PATH中加入$MYSQL_HOME/bin
在CMD命令下执行
# 安装数据库
mysqld --install
# 初始化数据库
mysqld --initialize --console # 此命令结束后会打印root默认密码
# 启动数据库
net start mysql
# 停止数据库
net stop mysql
# 登录数据库
mysql -u root -p
# 创建数据库、建表、建用户等等....
问题处理
问题1
提示错误信息:ERROR 1130
I had the same message after a fresh installation with the no-install zip and solved it as follows. Perhaps this could have been a solution for your problem too:
- Stop the MySQL server or service.
- Open a Command Prompt window with administrative rights and go to the bin folder in the MySQL install directory.
- Start MySQL with skip-grants-table and don’t forget your config file:
mysqld –defaults-file=[filename] –skip-grant-tables
Open another Command Prompt window and go to the bin folder again.
Now you can login:
mysql -u root -p
- Show the users with:
SELECT user, host FROM mysql.user;
Verify there is one ‘root’ with host ’localhost’.
Change the host:
UPDATE mysql.user SET host=’%’ WHERE user=‘root’;
Exit the mysql program and close the Command Prompt window.
Type Ctrl-C in the other Command Prompt window to stop the server, then close the Command Prompt Window.
Start MySQL as you normally would and verify that you can login.
问题2
提示错误信息:系统找不到制定的文件。
打开注册表 “我的计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\MySQL"下ImagePath配置改成"D:\Program Files\mysql-5.7.41-winx64\bin\mysqld” MySQL
问题3
忘记root用户密码
- 在my.ini配置文件中加入
skip-grant-tables
- 重新启停mysql,在用root免密码方式登录
- 修改密码
UPDATE user SET authentication_string=password('xxxxxx') WHERE user='root';
最后
简单记录下简答安装过程,以免后续还需要用。