在musql的目录新建一个my.ini,内容如下
[mysql]
设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
设置3306端口
port = 3306
设置mysql的安装目录
basedir=c:mysqlmysql-5.7.17-winx64
设置mysql数据库的数据的存放目录
datadir=c:mysqlmysql-5.7.17-winx64data
允许最大连接数
max_connections=500
服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
以管理员身份打开cmd窗口后,将目录切换到你mysql安装目录的bin目录,分别执行下面语句
mysqld --initialize-insecure --user=mysql
mysqld install
net start mysql
然后输入
mysql -u root -p
提示输入密码,直接敲回车即可登录,登录之后执行SET PASSWORD = PASSWORD('123456');修改密码为123456
然后就可以通过mysql -u root -p123456登录了,记住-p和密码之间是没有空格的。
添加mysql的普通用户sun_mysql,密码设置为123456
create user 'sun_mysql'@'localhost' identified by '123456';
设置该用户运行指定IP访问
GRANT ALL PRIVILEGES ON . TO 'sun_mysql'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;
在root用户下创建testdb库
grant all privileges on testdb.* to 'sun_mysql'@'%' identified by '123456';
flush privileges;
如果需要修改设置该用户只允许本机访问输入
delete from user where user = 'sun_mysql' and host != 'localhost';
GRANT ALL PRIVILEGES ON . TO 'sun_mysql'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;
如果设置mysql运行指定的IP访问
GRANT ALL PRIVILEGES ON . TO 'sun_mysql'@'110.110.110.46' IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;