
sidebar.wechat

sidebar.feishu
sidebar.chooseYourWayToJoin

sidebar.scanToAddConsultant
This article will guide you step-by-step to connect your first MySQL datasource to AskTable, enabling you to complete the entire process from zero to usable within 30 minutes.
Required:
Optional:
Time: 30 minutes
Check MySQL version:
mysql --version
# Example output: mysql Ver 8.0.32 for Linux on x86_64
Check if MySQL is running:
# Linux/Mac
sudo systemctl status mysql
# Or
ps aux | grep mysql
Check network connectivity:
# Test local connection
mysql -h localhost -u root -p
# Test remote connection
mysql -h your_host -P 3306 -u root -p
If you don't have a database yet, you can create a test database.
-- Connect to MySQL
mysql -u root -p
-- Create database
CREATE DATABASE demo_shop CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- Use database
USE demo_shop;
-- Users table
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'User ID',
name VARCHAR(100) NOT NULL COMMENT 'User Name',
email VARCHAR(100) COMMENT 'Email',
phone VARCHAR(20) COMMENT 'Phone Number',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation Time'
) COMMENT='Users Table';
-- Products table
CREATE TABLE products (
id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'Product ID',
name VARCHAR(200) NOT NULL COMMENT 'Product Name',
category VARCHAR(50) COMMENT 'Product Category',
price DECIMAL(10,2) NOT NULL COMMENT 'Price',
stock INT DEFAULT 0 COMMENT 'Stock',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation Time'
) COMMENT='Products Table';
-- Orders table
CREATE TABLE orders (
id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'Order ID',
user_id INT NOT NULL COMMENT 'User ID',
product_id INT NOT NULL COMMENT 'Product ID',
quantity INT NOT NULL COMMENT 'Quantity',
total_amount DECIMAL(10,2) NOT NULL COMMENT 'Total Amount',
status VARCHAR(20) DEFAULT 'pending' COMMENT 'Order Status',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation Time',
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (product_id) REFERENCES products(id)
) COMMENT='Orders Table';
-- Insert users
INSERT INTO users (name, email, phone) VALUES
('Zhang San', 'zhangsan@example.com', '13800138000'),
('Li Si', 'lisi@example.com', '13800138001'),
('Wang Wu', 'wangwu@example.com', '13800138002');
-- Insert products
INSERT INTO products (name, category, price, stock) VALUES
('iPhone 15', 'Phone', 5999.00, 100),
('MacBook Pro', 'Computer', 12999.00, 50),
('AirPods Pro', 'Earphones', 1999.00, 200);
-- Insert orders
INSERT INTO orders (user_id, product_id, quantity, total_amount, status) VALUES
(1, 1, 1, 5999.00, 'paid'),
(1, 3, 2, 3998.00, 'paid'),
(2, 2, 1, 12999.00, 'pending'),
(3, 1, 1, 5999.00, 'shipped');
For security, we create a read-only user for AskTable.
-- Create read-only user
CREATE USER 'asktable_readonly'@'%' IDENTIFIED BY 'your_strong_password_here';
-- If allowing only specific IP access
CREATE USER 'asktable_readonly'@'123.456.789.0' IDENTIFIED BY 'your_strong_password_here';
Password Requirements:
-- Grant read-only permissions for demo_shop database
GRANT SELECT ON demo_shop.* TO 'asktable_readonly'@'%';
-- Grant permission to view table structures
GRANT SHOW VIEW ON demo_shop.* TO 'asktable_readonly'@'%';
-- Refresh permissions
FLUSH PRIVILEGES;
-- View user permissions
SHOW GRANTS FOR 'asktable_readonly'@'%';
-- Should see similar output:
-- GRANT SELECT, SHOW VIEW ON `demo_shop`.* TO `asktable_readonly`@`%`
# Test if new user can connect
mysql -h localhost -u asktable_readonly -p demo_shop
# Test query
SELECT * FROM users LIMIT 1;
# Test write (should fail)
INSERT INTO users (name) VALUES ('test');
# Should report error: ERROR 1142 (42000): INSERT command denied
# View MySQL configuration
cat /etc/mysql/mysql.conf.d/mysqld.cnf | grep bind-address
# If it's 127.0.0.1, need to change to 0.0.0.0
Modify Configuration:
# /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
bind-address = 0.0.0.0
Restart MySQL:
sudo systemctl restart mysql
Linux (iptables):
# Allow port 3306
sudo iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
# Save rules
sudo iptables-save
Linux (firewalld):
# Allow MySQL service
sudo firewall-cmd --permanent --add-service=mysql
sudo firewall-cmd --reload
Cloud Servers:
# Test from another machine
mysql -h your_server_ip -P 3306 -u asktable_readonly -p demo_shop
Visit asktable.com and log in.
Step 1: Enter Datasource Page
Step 2: Select Database Type
Step 3: Fill in Connection Information
Name: Demo Shop
Host: your_server_ip
Port: 3306
Database: demo_shop
Username: asktable_readonly
Password: your_strong_password_here
Step 4: Advanced Configuration (Optional)
{
"ssl": false,
"charset": "utf8mb4",
"timezone": "+08:00"
}
Step 5: Test Connection
Step 6: Save Datasource
Step 1: Select Tables
Step 2: Start Sync
Step 3: View Metadata
In AskTable, input:
Query all users
Expected Result:
SELECT * FROM usersCount the number of products in each product category
Expected Result:
SELECT category, COUNT(*) as count FROM products GROUP BY categoryQuery the total order amount for each user
Expected Result:
SELECT u.name, SUM(o.total_amount) as total
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
GROUP BY u.id, u.name
Error Message:
Connection timeout
Solution:
Test Command:
telnet your_server_ip 3306
Error Message:
Access denied for user 'asktable_readonly'@'xxx.xxx.xxx.xxx'
Solution:
Fix Command:
-- Delete old user
DROP USER 'asktable_readonly'@'%';
-- Recreate
CREATE USER 'asktable_readonly'@'%' IDENTIFIED BY 'new_password';
GRANT SELECT ON demo_shop.* TO 'asktable_readonly'@'%';
FLUSH PRIVILEGES;
Error Message:
Unknown database 'demo_shop'
Solution:
Check Command:
SHOW DATABASES;
Error Message:
SSL connection error
Solution:
Configuration:
{
"ssl": false
}
Symptom: Chinese characters display as garbled text
Solution:
{
"charset": "utf8mb4"
}
-- Add indexes for commonly queried fields
CREATE INDEX idx_user_email ON users(email);
CREATE INDEX idx_product_category ON products(category);
CREATE INDEX idx_order_user_id ON orders(user_id);
CREATE INDEX idx_order_created_at ON orders(created_at);
-- Add more detailed comments
ALTER TABLE users MODIFY COLUMN name VARCHAR(100) COMMENT 'User Name (Required)';
ALTER TABLE products MODIFY COLUMN price DECIMAL(10,2) COMMENT 'Product Price (Unit: Yuan)';
Configure in AskTable:
{
"pool": {
"min_size": 2,
"max_size": 10,
"connect_timeout": 10
}
}
Generate SSL Certificate:
# On MySQL server
mysql_ssl_rsa_setup --datadir=/var/lib/mysql
Configure MySQL:
[mysqld]
require_secure_transport=ON
Enable SSL in AskTable:
{
"ssl": true,
"ssl_ca": "/path/to/ca.pem"
}
-- Allow only specific IP access
CREATE USER 'asktable_readonly'@'123.456.789.0' IDENTIFIED BY 'password';
GRANT SELECT ON demo_shop.* TO 'asktable_readonly'@'123.456.789.0';
-- Change password
ALTER USER 'asktable_readonly'@'%' IDENTIFIED BY 'new_password';
FLUSH PRIVILEGES;
Congratulations! You have successfully connected your first datasource.
Continue Learning:
Practice Suggestions:
Get Help:
Related Reading:
Technical Exchange:
sidebar.noProgrammingNeeded
sidebar.startFreeTrial