we do create many databases every day and i love UTF-8 data formate so i decided to make something simple and save my time
here is the syntax to create a database called unixawy in utf8
1 |
CREATE DATABASE `unixawy` CHARACTER SET utf8 COLLATE utf8_general_ci; |
to add a user for unixawy with password unixawysecret
1 2 |
GRANT ALL ON `test1`.* TO 'unixawy'@'localhost' IDENTIFIED BY 'unixawysecret'; FLUSH PRIVILEGES; |
also, i made a simple script to save my time
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
#!/usr/bin/env python #MYSQL CREATE UTF8 DATABASE WITH ACCESS USERNAME & PASSWORD #Ahmed Mahfouz AKA _N1X_ import sys,os mysql_root="root" mysql_pwd="mysqlrootpassword_here" hostname="localhost" try: db = sys.argv[1] username = sys.argv[2] password = sys.argv[3] create_db = "CREATE DATABASE " + "`"+ db + "`" + " CHARACTER SET utf8 COLLATE utf8_general_ci;" adddb_user = "GRANT ALL ON `" + db + "`.* TO '" + username+ "'@'localhost' IDENTIFIED BY " +"'"+ password + "';" reload = "FLUSH PRIVILEGES;" show_query = raw_input("Do u want to show mysql query Y/N (default N)") if show_query.lower() == 'y': print create_db print adddb_user print reload update_db = raw_input("if you want to apply prees Y/N: ") if update_db.lower() == 'y': sql_create = "echo %s|mysql -u %s -p%s -h%s" %(create_db.strip(";").replace("`","`"),mysql_root,mysql_pwd,hostname) sql_adduser = "echo %s|mysql -u %s -p%s -h%s" %(adddb_user.strip(";").replace("`","`").replace("'","\\'"),mysql_root,mysql_pwd,hostname) sql_commit ="echo %s|mysql -u %s -p%s -h%s" %(reload.strip(";"),mysql_root,mysql_pwd,hostname) #print sql_create #print "x"*10 #print adddb_user #print sql_adduser print "Creating Database" os.system(sql_create) print "Adding User to Database" os.system(sql_adduser) print "Finishing" os.system(sql_commit) except IndexError: print "usage: python mysql_db_user_pass_gen.py database_name username password" exit() |