Tôi muốn cài đặt một Database Server ở máy tính do công ty phát để phục vụ công việc. Tuy nhiên việc không có user admin là một trở ngại lớn. Vì vậy tôi quyết định dùng MySQL Server bản community, dạng zip file noinstall. Bài viết sau sẽ hướng dẫn nhanh cách cài đặt trên window.
- Download bộ cài ở đường dẫn sau: https://dev.mysql.com/downloads/mysql/
- Giải nén file zip ra. . Ví dụ: D:\mysql-8.0.23-winx64\
- Mở command line window hoặc và vào thư mục bin. Ví dụ: D:\mysql-8.0.23-winx64\bin
Note: Để thuận tiện tôi thường sử dụng tool Cmder hoặc Console 2 thay cho command line mặc định của window.
- Link download: https://cmder.app/
- Link download https://sourceforge.net/projects/console/
- Install: Giải nén và run Cmder.exe
4. Khởi tạo MySql Server database bằng cách chạy câu lệnh sau trên command line:
mysqld --initialize --console
MySQL Server sinh ra account mặc định là: root
Hệ thống sẽ chạy ra kết quả như màn hình bên dưới sau, tìm đến dòng có chưa Password mặc định Mysql sinh ra lần đầu. Lưu giữ lại thông tin này.
2024-09-25T08:25:35.006397Z 0 [System] [MY-015017] [Server] MySQL Server Initialization – start.
2024-09-25T08:25:35.017582Z 0 [System] [MY-013169] [Server] D:\mysql-8.4.0-winx64\bin\mysqld.exe (mysqld 8.4.0) initializing of server in progress as process 23164 2024-09-25T08:25:35.055369Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2024-09-25T08:25:35.606265Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2024-09-25T08:25:37.518081Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: >cRof8l;i,8. 2024-09-25T08:25:39.403136Z 0 [System] [MY-015018] [Server] MySQL Server Initialization – end. |
Cũng có thể vào thư mục D:\mysql-8.0.23-winx64\data. Bạn mở file [Ten May Ban].err là file log do MySQL sinh ra. Trong này sẽ có chứa password của account root.
5.Sau khi chạy xong câu lệnh trên thì sẽ khởi động server ở chế độ xem log trên command line bằng câu lệnh sau:
mysqld --console
Hình ảnh sau cho biết bạn đã start server thành công
6. Connect vào Mysql server bằng Mysql client command line để test.
Trên command line console 2, tạo thêm 1 tab nữa.
Chạy thử lênh sau:
D:\mysql-8.0.23-winx64\bin>mysql
Bạn sẽ thấy bị lỗi “””ERROR 1045 (28000): Access denied for user ‘ODBC’@’localhost’ (using password: NO)”
Chạy lại lênh như hình sau với account/password root như đã có ở phía trên.
7. Change password mặc định.
Tại dấu nhắc command line của Mysql client. gõ lệnh bên dưới.
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';
8.Restart server ở chế độ normal mode.
mysqld --console
Connect bằng mysql client
mysql -u root -p
Nhập password (MyNewPass) khi được hỏi.
Bây giờ bạn có thể query thao tác trên Mysql server bằng account với mật khẩu mới.
Good job