It is troublesome to install the db2 database directly on the host machine, and it is inconvenient to involve users and permissions, so docker is used to install the db2 database. The advantage of this is that it facilitates database management and network isolation. Docker is generally run directly on the Internet, which is not convenient for later modification. We still use the docker-compose file to install the db2 database. 1. Write the docker-compose file to automatically download the database image Just create a folder for this file. version: "2.2" services: db2: image: ibmcom/db2 container_name: db211.5 privileged: true environment: LICENSE: accept DB2INST1_PASSWORD: your password DBNAME: TESTDB volumes: - ./db2data:/database ports: - 50000:50000 2. Check the installation log and wait for DB2 initialization to complete, which may take several minutes #Execute docker-compose to start the installation docker-compose up -d #View the installation log docker-compose logs #It will be installed almost when TESTDB is created 3. Enter the db2 database container to create your own database #Enter the container docker exec -it db211.5 bash #Switch to db2inst1 user su db2inst1 #Check if there is our TESTDB database db2 list db directory 4. Create a user and grant permissions Other permissions can be found online. Here is a simple connection and add, delete, modify and check permissions. #Create user group groupadd db2group #Add the user to the group useradd -m -g db2group -d /home/test test #Change the test password to passwd test #Enter the password twice in succession #Switch to the db2inst1 user and grant connection permissions to test su db2inst1 #Connect to database db2 connect to testdb #Grant connection permissions db2 grant connect on database to user test #Give permissions for adding, deleting, modifying and checking db2 grant DATAACCESS on database to user test #Close the connection db2 connect reset #Other common commands#Create a database db2 create db TEST using codeset utf-8 territory CN #View all current databases db2 list db directory #View the table names in the library db2 list tables #More commands omitted 5. DB2 export and import operation commands #db2 export command (many files will appear, package them all) db2move <your databases> export #db2 import command (copy the packaged file to the server you want to import, and then execute the following command in the folder directory) db2move <your databases> import #If there is a permission problem, use the root user to grant writable permissions to the folder, because the import command will create an import.out file At this point, the installation of docker for db2 is completed. The advantage of using docker containers is that they can be seamlessly migrated between servers, making it very convenient to migrate databases to other servers in the future. Additional knowledge: Install db2 in docker and mount it locally 1. Find all db2 images
2. Pull the image I use the latest version of the image here. If you don't need the latest version, you can specify the version according to your own situation. Method: docker pull db2:11.5.4.0
3. Start the container and mount
Parameter Description: -d: means starting the container in the background; -p 50001:50000: The 50000 port in the container is mapped to the 50000 port on the host; --name db2_50001: Name the container db2_50001 --privileged=true: enables the root in the container to have real root permissions. -e DB2INST1_PASSWORD=123456: Set the password of the built-in instance user db2inst1 to 123456 -e DBNAME=testdb: A database named testdb is automatically created when the container starts. If this parameter is not specified, no database is created. -e LICENSE=accept: accept the agreement -v /data/tadopDataProject/db2/50001:/database: mount directory, where /data/tadopDataProject/db2/50001 is the directory of the host machine 4. Check whether the startup is successful
5. Enter the container and execute the db2 command
Execute the following command to switch to the instance user db2inst1: Note: Be sure to write the middle horizontal bar (-).
Check the running status:
View the database and patch versions:
View the created database:
Execute the command to connect to the testdb database:
Create a table called TEST: Note: The SQL statement following the db2 command needs to be enclosed in quotation marks, otherwise the error -bash: syntax error near unexpected token `(' will be reported.
View all user tables:
We can also execute the following command to create a SAMPLE database (sample database):
Execute the db2 list dbdirectory command again to check whether the creation is successful. Finally, execute exit to exit the container and return to the host machine. Connect to the testdb database The above docker-compose installation db2 database operation is all the content that the editor shares with you. I hope it can give you a reference, and I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: XHTML tutorial, a brief introduction to the basics of XHTML
>>: js to create a carousel effect
CEP - Complex Event Processing. The payment has n...
Use JS to complete a simple calculator for your r...
In the previous article, we introduced how to use...
Table of contents 1. Ternary operator judgment 2....
Intersection Selector The intersection selector i...
1. Command Introduction The passwd command is use...
1. Try to use single column instead of multi-colum...
This article introduces the sample code of CSS3 t...
This article uses examples to illustrate the prin...
Table of contents Nesting Parent-child component ...
The detailed process of using MySQL database with...
Table of contents 1. Offline installation 2. Onli...
· 【Scene description】 After HTTP1.1, the HTTP pro...
Front-end is a tough job, not only because techno...