Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7862447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:07:52+00:00 2026-06-02T23:07:52+00:00

there I am writting a simple app in Python that will monitor the usage

  • 0

there I am writting a simple app in Python that will monitor the usage of my cpu and ram and put it into a MySQL database for future processing here is my code :

import MySQLdb
import psutil


connection = MySQLdb.connect(host="localhost", port=8888, user="root", passwd="root", db="monitoring", unix_socket="/Applications/MAMP/tmp/mysql/mysql.sock")
c = connection.cursor()

while True:

    usage = psutil.cpu_percent(interval=1)

    c.execute("INSERT INTO cpu (usage) VALUES (%s)", (usage))

    c.execute("SELECT * FROM cpu")
    print c.fetchall()

Here is the libary that I am using for for monitoring

Here is a dump for MySQL database :

    --
-- Table structure for table `cpu`
--

    CREATE TABLE `cpu` (
      `id` int(12) NOT NULL AUTO_INCREMENT,
      `usage` float NOT NULL,
      `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=2 ;

However I am unable to fix this error when making an INSERT :

_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'usage) VALUES (12.9)' at line 1")

Any tips to fix this ?
I am sorry, but I am new to Python 🙂

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:07:54+00:00Added an answer on June 2, 2026 at 11:07 pm

    This is not a Python issue. The problem is that usage is a reserved word in MySQL. You should either change the name of your column to something else, or use backticks to quote it in your code:

    c.execute("INSERT INTO cpu (`usage`) VALUES (%s)", (usage))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a simple Windows app in c++, that will be able to
I am writing a simple win forms app in C#. There is a method
I'm writing a simple .bat file and I've run into some weird behavior. There
Im new to python programming.Im writing a simple command line based twitter app,and i
I'm in the process of writing a simple console app that monitors a particular
Assume that you are writing a simple app. The model is that a 'project'
I'm learning Rails, and got into a little problem. I'm writing dead simple app
I am writing a simple business app that retrieves data from a server for
I am writing an auto update client. It's a very simple app that: 1)
I am writing a simple app that requires a field of input via an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.