Run ClickHouse with Docker and Connect Using MySQL Client
Zhe8 min read
We do not find detailed instruction on running ClickHouse with Docker on the web, so we decide to provide our own step-by-step tutorial.
Background
ClickHouseยฎ is an open-source, high performance columnar OLAP database management system for real-time analytics using SQL.
Docker is a software platform allowing developers to build, test, and deploy applications quickly. Docker packages software into container, a standardized unit abstracting the underlying operating system.
Run the following command to start a ClickHouse server in a docker container.
Client
Run the following command to connect to ClickHouse server with the default user.
Configuration
Enable SQL-driven access control and account management for the default user
By default, the ClickHouse server provides the default user account which is not allowed using SQL-driven access control and account management but has all the rights and permissions. To enable it, we need to edit a server configuration file.
Run
which copies it to your current directory (don't miss the last dot) on your local machine. Then use whatever editor you want to edit the file locally.
In users.xml, add <access_management>1</access_management>.
After the change, the file structure should be something like
Note that this is unsafe and you should change it back to <access_management>0</access_management> after finishing your work.
And then run
to replace the old one.
Create a user
You can check the users with SHOW USERS command.
Create a database
You can check the databases with the SHOW DATABASES command.
Grant database privileges to the user
Connect with the new user
Now we can connect to the server with the created user.
You can run SHOW GRANTS to see the permissions the user has.
Create a table and run some queries
To create a table.
Run SHOW TABLES to check the tables.
Run DESCRIBE TABLE employees. You will see something like
Do some inserts.
Finally, we can run some queries now.
Connect to ClickHouse Server with MySQL Client
ClickHouse supports MySQL wire protocol. It can be enabled by mysql_port setting in configuration file: /etc/clickhouse_server/config.xml.
By default, it should be<mysql_port>9004</mysql_port>.
Server
We start a ClickHouse server with the following command, notice that port 9004 is exposed this time.
Client
Example of connecting using command-line tool mysql:
Output if a connection succeeded:
Conclusion
You've just started a ClickHouse server using docker, connected to it, created a user, a database, a table, and executed some queries against it. You've also learned how to connect to ClickHouse server using MySQL client.
If you like this tutorial, you might also be interested in our product Bytebase, an open source, web-based schema change management tool, which helps you manage ClickHouse database, supporting SQL review, version control, backup and restore and etc...
At Bytebase, we believe in the power of collaboration and open communication, and we have a number of communities that you can join to connect with other like-minded.