Run ClickHouse with Docker and Connect Using MySQL Client
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.
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.
Install docker before you continue.
Run the following command to start a ClickHouse server in a docker container.
Run the following command to connect to ClickHouse server with the default user.
Enable SQL-driven access control and account management for the
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.
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
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.
SHOW TABLES to check the tables.
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:
By default, it should be
We start a ClickHouse server with the following command, notice that port 9004 is exposed this time.
Example of connecting using command-line tool
Output if a connection succeeded:
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...