Getting Started with MySQL on Railway
You can provision a MySQl database through either the Railway Dashboard or the Railway CLI.
Outline
1. Railway Dashboard
dev.new and choose "Provision MySQL"
ClickAfter the database is setup click "MySQL" on the left and then choose "Connect".
Copy and paste the MySQL client command.
Your own password will be included in place of xxxx
.
mysql -hcontainers-us-west-8.railway.app -uroot -xxxx --port 7551 --protocol=TCP railway
(download MySQL with brew install mysql
)
Run the following SQL commands to create a test table with seed data
CREATE TABLE test_table (Test text);
INSERT INTO test_table VALUES ('Hello'), ('Goodbye');
show tables;
Output:
+-------------------+
| Tables_in_railway |
+-------------------+
| test_table |
+-------------------+
1 row in set (0.04 sec)
2. Railway CLI
Railway CLI
First you need to install the Railway CLI.
Check Railway CLI version
railway version
railway version 0.2.40
railway login
Login with If you do not have a Railway account you will be prompted to create one.
railway login
railway init
Initialize project with Run the following command, select “Empty Project,” and give your project a name.
railway init
railway add
Provision MySQL with Run the following command and select MySQL to add a plugin to your Railway project.
railway add
Link to your project
railway link
Select your newly created project from the list.
Connect to database
railway connect mysql
Seed database
Run the following SQL commands to create a test table with seed data.
CREATE TABLE Post (title text, body text);
INSERT INTO Post VALUES ('This is a blog post', 'Wooooooo');
INSERT INTO Post VALUES ('Another blog post', 'Even better than the other!');
List tables in database
SHOW TABLES;
+-------------------+
| Tables_in_railway |
+-------------------+
| Post |
+-------------------+
1 row in set (0.04 sec)
Quit mysql
quit