Find answers from the community

Updated 10 months ago

from llama_index.readers.database import

from llama_index.readers.database import DatabaseReader

reader = DatabaseReader(
scheme=os.getenv("mysql"),
host=os.getenv("localhost"),
port=os.getenv("3306"),
user=os.getenv("root"),
password=os.getenv("password"),
dbname=os.getenv("databasename"),
)

query = "SELECT * FROM users"
documents = reader.load_data(query=query)

Can anyone help me with the error?

ValueError Traceback (most recent call last)
Cell In[52], line 5
1 from llama_index.core import download_loader
3 from llama_index.readers.database import DatabaseReader
----> 5 reader = DatabaseReader(
6 scheme=os.getenv("mysql"),
7 host=os.getenv("localhost"),
8 port=os.getenv("3306"),
9 user=os.getenv("root"),
10 password=os.getenv("password"),
11 dbname=os.getenv("databasename"),
12 )
14 query = "SELECT * FROM users"
15 documents = reader.load_data(query=query)

File ~\anaconda\lib\site-packages\llama_index\readers\database\base.py:70, in DatabaseReader.init(self, sql_database, engine, uri, scheme, host, port, user, password, dbname, *args, kwargs) 68 self.sql_database = SQLDatabase.from_uri(uri, *args, kwargs)
69 else:
---> 70 raise ValueError(
71 "You must provide either a SQLDatabase, "
72 "a SQL Alchemy Engine, a valid connection URI, or a valid "
73 "set of credentials."
74 )

ValueError: You must provide either a SQLDatabase, a SQL Alchemy Engine, a valid connection URI, or a valid set of credentials.
W
2 comments
I think you are picking out the env values incorrectly πŸ‘€
For instance, os.getenv("3306"), If you want to provide the value directly you can pass it directly.

Else if you want to pick from env ( Ideal case )
Set the value to a variable in your env and then pick like:

DATABASE_READER_PORT=3306

Then in your code:
reader = DatabaseReader(port=os.getenv('DATABASE_READER_PORT',...)
Add a reply
Sign up and join the conversation on Discord