Python Importing mysql to csv file
up vote
0
down vote
favorite
I have a code in python that export mysql to csv file here is the output.
im also using python 3.6
b'USER1'|b'rona1'|b'pass1'
b'USER2'|b'rona2'|b'pass2'
b'USER3'|b'rona3'|b'pass3'
and i want the output is
USER1|rona1|pass1
USER2|rona2|pass2
USER3|rona3|pass3
Here is my code in python:
import mysql.connector
from UnicodeSupportForCsv import UnicodeWriter
import csv
import sys
config = {'user': 'root',
'password': 222222,
'host': 'localhost',
'port':221,'database':
'server_mysql_sample',
'raise_on_warnings': True
}
connect = mysql.connector.connect(**config)
dbquery='Select * from tbl_user;'
conn = mysql.connector.connect(**config)
crsr = conn.cursor()
crsr.execute("SELECT * FROM tbl_user")
with open(r'test.csv', 'wb') as csvfile:
uw = UnicodeWriter(
csvfile, delimiter='|',quotechar='"', quoting=csv.QUOTE_NONE)
for row in crsr.fetchall():
uw.writerow([str(col) for col in row])
then i used the unicodewriter from https://docs.python.org/2/library/csv.html
and i remove data = data.decode("utf-8") to make it work.
but the output is b'text'|b'text'|b'text'
python mysql export-to-csv
add a comment |
up vote
0
down vote
favorite
I have a code in python that export mysql to csv file here is the output.
im also using python 3.6
b'USER1'|b'rona1'|b'pass1'
b'USER2'|b'rona2'|b'pass2'
b'USER3'|b'rona3'|b'pass3'
and i want the output is
USER1|rona1|pass1
USER2|rona2|pass2
USER3|rona3|pass3
Here is my code in python:
import mysql.connector
from UnicodeSupportForCsv import UnicodeWriter
import csv
import sys
config = {'user': 'root',
'password': 222222,
'host': 'localhost',
'port':221,'database':
'server_mysql_sample',
'raise_on_warnings': True
}
connect = mysql.connector.connect(**config)
dbquery='Select * from tbl_user;'
conn = mysql.connector.connect(**config)
crsr = conn.cursor()
crsr.execute("SELECT * FROM tbl_user")
with open(r'test.csv', 'wb') as csvfile:
uw = UnicodeWriter(
csvfile, delimiter='|',quotechar='"', quoting=csv.QUOTE_NONE)
for row in crsr.fetchall():
uw.writerow([str(col) for col in row])
then i used the unicodewriter from https://docs.python.org/2/library/csv.html
and i remove data = data.decode("utf-8") to make it work.
but the output is b'text'|b'text'|b'text'
python mysql export-to-csv
Possible duplicate of Python: Write Unicode to CSV using UnicodeWriter
– kcorlidy
Nov 22 at 9:45
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a code in python that export mysql to csv file here is the output.
im also using python 3.6
b'USER1'|b'rona1'|b'pass1'
b'USER2'|b'rona2'|b'pass2'
b'USER3'|b'rona3'|b'pass3'
and i want the output is
USER1|rona1|pass1
USER2|rona2|pass2
USER3|rona3|pass3
Here is my code in python:
import mysql.connector
from UnicodeSupportForCsv import UnicodeWriter
import csv
import sys
config = {'user': 'root',
'password': 222222,
'host': 'localhost',
'port':221,'database':
'server_mysql_sample',
'raise_on_warnings': True
}
connect = mysql.connector.connect(**config)
dbquery='Select * from tbl_user;'
conn = mysql.connector.connect(**config)
crsr = conn.cursor()
crsr.execute("SELECT * FROM tbl_user")
with open(r'test.csv', 'wb') as csvfile:
uw = UnicodeWriter(
csvfile, delimiter='|',quotechar='"', quoting=csv.QUOTE_NONE)
for row in crsr.fetchall():
uw.writerow([str(col) for col in row])
then i used the unicodewriter from https://docs.python.org/2/library/csv.html
and i remove data = data.decode("utf-8") to make it work.
but the output is b'text'|b'text'|b'text'
python mysql export-to-csv
I have a code in python that export mysql to csv file here is the output.
im also using python 3.6
b'USER1'|b'rona1'|b'pass1'
b'USER2'|b'rona2'|b'pass2'
b'USER3'|b'rona3'|b'pass3'
and i want the output is
USER1|rona1|pass1
USER2|rona2|pass2
USER3|rona3|pass3
Here is my code in python:
import mysql.connector
from UnicodeSupportForCsv import UnicodeWriter
import csv
import sys
config = {'user': 'root',
'password': 222222,
'host': 'localhost',
'port':221,'database':
'server_mysql_sample',
'raise_on_warnings': True
}
connect = mysql.connector.connect(**config)
dbquery='Select * from tbl_user;'
conn = mysql.connector.connect(**config)
crsr = conn.cursor()
crsr.execute("SELECT * FROM tbl_user")
with open(r'test.csv', 'wb') as csvfile:
uw = UnicodeWriter(
csvfile, delimiter='|',quotechar='"', quoting=csv.QUOTE_NONE)
for row in crsr.fetchall():
uw.writerow([str(col) for col in row])
then i used the unicodewriter from https://docs.python.org/2/library/csv.html
and i remove data = data.decode("utf-8") to make it work.
but the output is b'text'|b'text'|b'text'
python mysql export-to-csv
python mysql export-to-csv
edited Nov 22 at 7:25
Sven Harris
1,6871211
1,6871211
asked Nov 22 at 7:17
James Smith
11
11
Possible duplicate of Python: Write Unicode to CSV using UnicodeWriter
– kcorlidy
Nov 22 at 9:45
add a comment |
Possible duplicate of Python: Write Unicode to CSV using UnicodeWriter
– kcorlidy
Nov 22 at 9:45
Possible duplicate of Python: Write Unicode to CSV using UnicodeWriter
– kcorlidy
Nov 22 at 9:45
Possible duplicate of Python: Write Unicode to CSV using UnicodeWriter
– kcorlidy
Nov 22 at 9:45
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425684%2fpython-importing-mysql-to-csv-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of Python: Write Unicode to CSV using UnicodeWriter
– kcorlidy
Nov 22 at 9:45