D:\Program Files\mysql\bin>mysqld --initialize --console 2019-02-14T11:47:59.282979Z 0 [System] [MY-013169] [Server] D:\Program Files\mysql\bin\mysqld.exe (mysqld 8.0.15) initializing of server in progress as process 13752 2019-02-14T11:47:59.284705Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous. 2019-02-14T11:48:40.707445Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 7CwffH5<(lem 2019-02-14T11:49:02.894787Z 0 [System] [MY-013170] [Server] D:\Program Files\mysql\bin\mysqld.exe (mysqld 8.0.15) initializing of server has completed
注意!执行输出结果里面有一段: [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 7CwffH5<(lem,D 其中root@localhost:后面的“7CwffH5<(lem,D”就是初始密码(不含首位空格)。在没有更改密码前,需要记住这个密码,后续登录需要用到。 要是你手贱,关快了,或者没记住,那也没事,删掉初始化的 datadir 目录,再执行一遍初始化命令,又会重新生成的。当然,也可以使用安全工具,强制改密码,用什么方法,自己随意。
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
修改密码,注意命令尾的;一定要有,这是mysql的语法
二、账号配置与使用测试
2.1 数据库的创建、表单和字段配置
创建数据库:iodata
创建数据库表单:teacher ,user_info
创建数据库表单中的字段:user_id,user_pass,user_modified 等等
设置数据库表单中的主键。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
CREATE DATABASE iodata; use iodata; /*show tables; create table teacher ( code varchar(20) primary key, name varchar(20) );*/ CREATE TABLE user_info ( ID int NOT NULL AUTO_INCREMENT,/* 设置自动加的用户ID*/ user_id VARCHAR(200) NOT NULL,/*支持中英文200个字符的用户字符串*/ user_pass VARCHAR(200) NOT NULL, user_create datetime(3) NULL DEFAULT CURRENT_TIMESTAMP(3), user_modified datetime(3) NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3), PRIMARY KEY (ID)/* 设置主键*/ );
2.2 配置数据库的用户访问账号密码,权限
1 2 3 4 5 6
use iodata; CREATE USER 'porter'@'localhost' IDENTIFIED BY 'shuruniziji_mima';/* 创建用户 */ INSERT INTO iodata.user_info ( user_id, user_pass) VALUES ( 'porter', '123'); grant all privileges on *.* to 'porter'@'%'; /* 放行用户的所有权限并允许远程网络连接 */
# -*- coding:utf-8 -*- import pymysql defget_loan_number(file): connect = pymysql.Connect( host="106.14.221.55", port=3306, user="nadersidc", passwd="366583", db="defect_detecting", charset='utf8' ) print("写入中,请等待……") cursor = connect.cursor() # sql = "select id from application where status='SUBMITTING' and contract like 'Performance-%' and " \ # "loan_org_party='166490194444444444'"
# sql = "select Element.Id,Element.FileName,DefectPosition.TopX,DefectPosition.TopY,\ # DefectPosition.Width,DefectPosition.Height from Element,DefectPosition where Element.DefectId=6 \ # and Element.ImageTypeId=2 and DefectPosition.ElementId=Element.Id"
# sql = "select * from Element LIMIT 1,5" # sql = "select * from * LIMIT 1,5" # 查询数据库表中所有的表名字 # sql = "select table_name from information_schema.tables where table_schema='defect_detecting'" sql = "select * from TrainProject LIMIT 1,5" cursor.execute(sql) number = cursor.fetchall() fp = open(file, "w") loan_count = 0 for loanNumber in number: loan_count += 1 fp.write(str(loanNumber)+'\n') fp.close() cursor.close() connect.close() print("写入完成,共写入%d条数据……" % loan_count)