avatar
童琦杰
Feb 3, 2018Technology

MySQL安装

Ubuntu下安装

bash
sudo apt-get install mysql-server

登录MYSQL

根用户登录

bash
mysql -u root -p

指定用户名密码登录

bash
mysql --user=user_name --password=your_password

创建用户

bash
CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'password';
CREATE USER 'user_name'@'%' IDENTIFIED BY 'password';

创建数据库、表

bash
CREATE SCHEMA `database_name`;
USE `database_name`;
CREATE TABLE `table_name` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `username` varchar(100) NOT NULL,
  `password` varchar(100) NOT NULL,
  `createTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `index_username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8mb4;

权限设置

bash
GRANT ALL PRIVILEGES ON `database_name`.* TO 'username'@'localhost';

远程访问

修改MYSQL监听IP

/etc/mysql/my.cnf
[mysqld]
bind-address=192.168.0.200;    # local IP Address

重启服务

bash
sudo /etc/init.d/mysql restart

日志查看

bash
vim /var/log/mysql/error.log

字符集

sql
CREATE TABLE `database`.`table` (
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ConnectionString: Server=;Database=;Uid=;Pwd=;Charset=utf8

Windows下二进制文件安装

解压二进制文件

初始化数据目录

bash
bin\mysqld --initialize --console

连接MYSQL

bash
mysql -u root -p
Enter password: (enter the random root password here)

重置根用户密码

bash
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

启动服务

bash
mysqld --console

停止服务

bash
mysqladmin -u root -p shutdown
© 2015-2022 tongqijie.com 版权所有沪ICP备17000682号