To create a Python script that interacts with a MySQL database, you'll need to install the `mysql-connector-python` package. You can do this by running:

```bash
pip install mysql-connector-python
```

Once you have the package installed, you can use the following script as a starting point for your project:

```python
import mysql.connector
from mysql.connector import Error

def create_connection():
    connection = None
    try:
        connection = mysql.connector.connect(
            host="localhost",
            user="your_username",
            password="your_password",
            database="books_db"
        )
        print("Connection to MySQL DB successful")
    except Error as e:
        print(f"The error '{e}' occurred")

    return connection


def execute_query(connection, query):
    cursor = connection.cursor()
    try:
        cursor.execute(query)
        connection.commit()
        print("Query executed successfully")
    except Error as e:
        print(f"The error '{e}' occurred")


def execute_read_query(connection, query):
    cursor = connection.cursor()
    result = None
    try:
        cursor.execute(query)
        result = cursor.fetchall()
        return result
    except Error as e:
        print(f"The error '{e}' occurred")


# Create the books table
create_books_table = """
CREATE TABLE IF NOT EXISTS books (
  id INT AUTO_INCREMENT,
  title VARCHAR(255) NOT NULL,
  author VARCHAR(255) NOT NULL,
  publication_date DATE NOT NULL,
  genre VARCHAR(255) NOT NULL,
  PRIMARY KEY (id)
);
"""

connection = create_connection()

execute_query(connection, create_books_table)

# Insert sample data into the books table
insert_book = """
INSERT INTO books (title, author, publication_date, genre) VALUES
('The Catcher in the Rye', 'J.D. Salinger', '1951-07-16', 'Fiction'),
('To Kill a Mockingbird', 'Harper Lee', '1960-07-11', 'Fiction');
"""

execute_query(connection, insert_book)

# Retrieve all books from the table
select_books = "SELECT * FROM books;"
books = execute_read_query(connection, select_books)

for book in books:
    print(book)
```

Replace `your_username` and `your_password` with your MySQL username and password. This script creates a connection to the database, creates a table for storing book information, inserts sample data into the table, and retrieves all records from the table.

Make sure you have created a database named `books_db` before running this script. You can create it using a MySQL client or by adding the following lines to the script:

```python
def create_database(connection, db_name):
    cursor = connection.cursor()
    try:
        cursor.execute(f"CREATE DATABASE {db_name};")
        print(f"Database '{db_name}' created successfully.")
    except Error as e:
        print(f"The error '{e}' occurred")

connection = create_connection()

create_database(connection, "books_db")
```

You can customize the script according to your needs, such as adding more functions for inserting, updating, and deleting records.
Write a Python script that interacts with a MySQL database to store and retrieve information about books, including title, author, publication date, and genre. Include error handling for invalid inputs.
