docker内centos安装mysql导入sql

[root@47b35a7762cc /]# dnf -y install mariadb-server
Last metadata expiration check: 0:24:20 ago on Thu 19 May 2022 01:55:58 AM UTC.
Dependencies resolved.
==================================================================================
 Package           Arch   Version                                 Repo       Size
==================================================================================
Installing:
 mariadb-server    x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d AppStream  16 M
Installing dependencies:
 libaio            x86_64 0.3.112-1.el8                           BaseOS     33 k
 mariadb-errmsg    x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d AppStream 234 k
 perl-DBD-MySQL    x86_64 4.046-3.module_el8.3.0+419+c2dec72b     AppStream 156 k
 perl-DBI          x86_64 1.641-3.module_el8.3.0+413+9be2aeb5     AppStream 740 k
 perl-Math-BigInt  noarch 1:1.9998.11-7.el8                       BaseOS    196 k
 perl-Math-Complex noarch 1.59-420.el8                            BaseOS    108 k
 psmisc            x86_64 23.1-5.el8                              BaseOS    151 k
Installing weak dependencies:
 mariadb-backup    x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d AppStream 6.1 M
 mariadb-gssapi-server
                   x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d AppStream  51 k
 mariadb-server-utils
                   x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d AppStream 1.1 M
Enabling module streams:
 perl-DBD-MySQL           4.046
 perl-DBI                 1.641

Transaction Summary
==================================================================================
Install  11 Packages

Total download size: 25 M
Installed size: 119 M
Downloading Packages:
(1/11): libaio-0.3.112-1.el8.x86_64.rpm            21 kB/s |  33 kB     00:01
(2/11): perl-Math-Complex-1.59-420.el8.noarch.rpm  56 kB/s | 108 kB     00:01
(3/11): perl-Math-BigInt-1.9998.11-7.el8.noarch.r  80 kB/s | 196 kB     00:02
(4/11): psmisc-23.1-5.el8.x86_64.rpm              155 kB/s | 151 kB     00:00
(5/11): mariadb-gssapi-server-10.3.28-1.module_el  96 kB/s |  51 kB     00:00
(6/11): mariadb-errmsg-10.3.28-1.module_el8.3.0+7  58 kB/s | 234 kB     00:04
(7/11): mariadb-server-utils-10.3.28-1.module_el8 137 kB/s | 1.1 MB     00:08
(8/11): perl-DBD-MySQL-4.046-3.module_el8.3.0+419 127 kB/s | 156 kB     00:01
(9/11): perl-DBI-1.641-3.module_el8.3.0+413+9be2a 170 kB/s | 740 kB     00:04
(10/11): mariadb-backup-10.3.28-1.module_el8.3.0+ 218 kB/s | 6.1 MB     00:28
(11/11): mariadb-server-10.3.28-1.module_el8.3.0+ 345 kB/s |  16 MB     00:47
----------------------------------------------------------------------------------
Total                                             499 kB/s |  25 MB     00:51
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                          1/1
  Installing       : libaio-0.3.112-1.el8.x86_64                             1/11
warning: Unable to get systemd shutdown inhibition lock: Unit systemd-logind.service is masked.

  Installing       : mariadb-errmsg-3:10.3.28-1.module_el8.3.0+757+d38299    2/11
  Installing       : psmisc-23.1-5.el8.x86_64                                3/11
  Installing       : perl-Math-Complex-1.59-420.el8.noarch                   4/11
  Installing       : perl-Math-BigInt-1:1.9998.11-7.el8.noarch               5/11
  Installing       : perl-DBI-1.641-3.module_el8.3.0+413+9be2aeb5.x86_64     6/11
  Installing       : perl-DBD-MySQL-4.046-3.module_el8.3.0+419+c2dec72b.x    7/11
  Installing       : mariadb-backup-3:10.3.28-1.module_el8.3.0+757+d38299    8/11
  Installing       : mariadb-gssapi-server-3:10.3.28-1.module_el8.3.0+757    9/11
  Installing       : mariadb-server-utils-3:10.3.28-1.module_el8.3.0+757+   10/11
  Running scriptlet: mariadb-server-3:10.3.28-1.module_el8.3.0+757+d38299   11/11
  Installing       : mariadb-server-3:10.3.28-1.module_el8.3.0+757+d38299   11/11
  Running scriptlet: mariadb-server-3:10.3.28-1.module_el8.3.0+757+d38299   11/11
  Verifying        : libaio-0.3.112-1.el8.x86_64                             1/11
  Verifying        : perl-Math-BigInt-1:1.9998.11-7.el8.noarch               2/11
  Verifying        : perl-Math-Complex-1.59-420.el8.noarch                   3/11
  Verifying        : psmisc-23.1-5.el8.x86_64                                4/11
  Verifying        : mariadb-backup-3:10.3.28-1.module_el8.3.0+757+d38299    5/11
  Verifying        : mariadb-errmsg-3:10.3.28-1.module_el8.3.0+757+d38299    6/11
  Verifying        : mariadb-gssapi-server-3:10.3.28-1.module_el8.3.0+757    7/11
  Verifying        : mariadb-server-3:10.3.28-1.module_el8.3.0+757+d38299    8/11
  Verifying        : mariadb-server-utils-3:10.3.28-1.module_el8.3.0+757+    9/11
  Verifying        : perl-DBD-MySQL-4.046-3.module_el8.3.0+419+c2dec72b.x   10/11
  Verifying        : perl-DBI-1.641-3.module_el8.3.0+413+9be2aeb5.x86_64    11/11

Installed:
  libaio-0.3.112-1.el8.x86_64
  mariadb-backup-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64
  mariadb-errmsg-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64
  mariadb-gssapi-server-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64
  mariadb-server-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64
  mariadb-server-utils-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64
  perl-DBD-MySQL-4.046-3.module_el8.3.0+419+c2dec72b.x86_64
  perl-DBI-1.641-3.module_el8.3.0+413+9be2aeb5.x86_64
  perl-Math-BigInt-1:1.9998.11-7.el8.noarch
  perl-Math-Complex-1.59-420.el8.noarch
  psmisc-23.1-5.el8.x86_64

Complete!
[root@47b35a7762cc /]# systemctl start mariadb.service
[root@47b35a7762cc /]# systemctl enable mariadb.service
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@47b35a7762cc /]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@47b35a7762cc /]# use mysql;
bash: use: command not found
[root@47b35a7762cc /]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> selcet User,authentication_string,Host from user;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'selcet User,authentication_string,Host from user' at line 1
MariaDB [mysql]> select User,authentication_string,Host from user;
+------+-----------------------+--------------+
| User | authentication_string | Host         |
+------+-----------------------+--------------+
| root |                       | localhost    |
| root |                       | 47b35a7762cc |
| root |                       | 127.0.0.1    |
| root |                       | ::1          |
+------+-----------------------+--------------+
4 rows in set (0.005 sec)

MariaDB [mysql]> Grant all privileges on *.* to 'root'@'%' identified by '123456789';
Query OK, 0 rows affected (0.004 sec)

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.006 sec)

MariaDB [mysql]> use bookstore;
ERROR 1049 (42000): Unknown database 'bookstore'
MariaDB [mysql]> creat database bookstore;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'creat database bookstore' at line 1
MariaDB [mysql]> create database bookstore;
Query OK, 1 row affected (0.005 sec)

MariaDB [mysql]> use bookstore;
Database changed
MariaDB [bookstore]> source /var/www/html/books.sql
Query OK, 0 rows affected (0.005 sec)

Query OK, 0 rows affected (0.001 sec)

Query OK, 0 rows affected, 1 warning (0.003 sec)

Query OK, 0 rows affected (0.064 sec)

Query OK, 0 rows affected (0.000 sec)

Query OK, 1 row affected (0.004 sec)

Query OK, 1 row affected (0.008 sec)

Query OK, 1 row affected (0.000 sec)

Query OK, 0 rows affected (0.025 sec)

Query OK, 0 rows affected (0.000 sec)

MariaDB [bookstore]> select * from books;
+----+--------------------+-------+--------+
| id | name               | price | author |
+----+--------------------+-------+--------+
|  1 | PHP项目实践        | 56.00 | 明     |
|  2 | Java基础           | 88.00 | 强     |
|  3 | Python数据分析     | 66.00 | 飞     |
+----+--------------------+-------+--------+
3 rows in set (0.008 sec)

 

[root@47b35a7762cc /]# dnf search php-mysql
Last metadata expiration check: 0:53:51 ago on Thu 19 May 2022 01:55:58 AM UTC.
============================ Name Matched: php-mysql =============================
php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
[root@47b35a7762cc /]# dnf install -y php-mysqlnd.x86_64
Last metadata expiration check: 0:54:17 ago on Thu 19 May 2022 01:55:58 AM UTC.
Dependencies resolved.
==================================================================================
Package Arch Version Repository Size
==================================================================================
Installing:
php-mysqlnd x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream 190 k
Installing dependencies:
php-pdo x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream 122 k

Transaction Summary
==================================================================================
Install 2 Packages

Total download size: 313 k
Installed size: 647 k
Downloading Packages:
(1/2): php-pdo-7.2.24-1.module_el8.2.0+313+b04d0a 7.6 kB/s | 122 kB 00:16
(2/2): php-mysqlnd-7.2.24-1.module_el8.2.0+313+b0 9.1 kB/s | 190 kB 00:20
----------------------------------------------------------------------------------
Total 15 kB/s | 313 kB 00:20
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : php-pdo-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 1/2
warning: Unable to get systemd shutdown inhibition lock: Unit systemd-logind.service is masked.

Installing : php-mysqlnd-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_6 2/2
Running scriptlet: php-mysqlnd-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_6 2/2
Verifying : php-mysqlnd-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_6 1/2
Verifying : php-pdo-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 2/2

Installed:
php-mysqlnd-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64
php-pdo-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64

Complete!
[root@47b35a7762cc /]# curl localhost:8001
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>测试页面</title>
<link type="text/css" rel="stylesheet" href="./css/base.css"/>
</head>
<body>
Hostname:
47b35a7762cc</p>
<img src="./img/1.png"/>
<img src="./efsimags/2.jpg"/>
<table>
<tr><th>序号</th><th>书名</th><th>作者</th><th>定价</th></tr>
<tr><td>1</td><td>PHP项目实践</td><td>明</td><td>56.00</td></tr><tr><td>2</td><td>Java基础</td><td>强</td><td>88.00</td></tr><tr><td>3</td><td>Python数据分析</td><td>飞</td><td>66.00</td></tr></table>
</body>
</html>
[root@47b35a7762cc /]#

 

[root@localhost ~]# docker run --privileged=true -itd -p 8001:8001 demo:v1.0
90886a2ca4bfb972797015a7d5bc62170a89cdb3e534041ae2b38f25754e04ca
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE         COMMAND            CREATED          STATUS                    PORTS                                       NAMES
90886a2ca4bf   demo:v1.0     "/usr/sbin/init"   33 seconds ago   Up 18 seconds             0.0.0.0:8001->8001/tcp, :::8001->8001/tcp   nostalgic_ptolemy
47b35a7762cc   centos        "/usr/sbin/init"   25 hours ago     Up 25 hours                                                           centos
6ae1ec8e9831   centos        "/bin/bash"        25 hours ago     Exited (0) 25 hours ago                                               quizzical_brattain
3cf501de1b36   centos        "/bin/bash"        25 hours ago     Exited (0) 25 hours ago                                               boring_edison
797b5d4c677e   hello-world   "/hello"           42 hours ago     Exited (0) 42 hours ago                                               elastic_hertz
fdc3b68b24cf   hello-world   "/hello"           8 days ago       Exited (0) 8 days ago                                                 reverent_davinci
3000b5215d50   ubuntu        "bash"             8 days ago       Exited (0) 8 days ago                                                 pensive_tharp
e417303870fc   hello-world   "/hello"           8 days ago       Exited (0) 8 days ago                                                 infallible_dijkstra
5532b4f63054   hello-world   "/hello"           8 days ago       Exited (0) 8 days ago                                                 admiring_morse
[root@localhost ~]# docker exec -it 90886a2ca4bf /bin/bash
[root@90886a2ca4bf /]# curl localhost:8001
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>测试页面</title>
    <link type="text/css" rel="stylesheet" href="./css/base.css"/>
</head>
<body>
Hostname:
90886a2ca4bf</p>
<img src="./img/1.png"/>
<img src="./efsimags/2.jpg"/>
<table>
    <tr><th>序号</th><th>书名</th><th>作者</th><th>定价</th></tr>
    <tr><td>1</td><td>PHP项目实践</td><td>明</td><td>56.00</td></tr><tr><td>2</td><td>Java基础</td><td>强</td><td>88.00</td></tr><tr><td>3</td><td>Python数据分析</td><td>飞</td><td>66.00</td></tr></table>
</body>
</html>
=====
Last login: Fri May 20 08:45:19 2022 from 192.168.163.1
[root@localhost ~]# curl localhost:8001
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>测试页面</title>
    <link type="text/css" rel="stylesheet" href="./css/base.css"/>
</head>
<body>
Hostname:
90886a2ca4bf</p>
<img src="./img/1.png"/>
<img src="./efsimags/2.jpg"/>
<table>
    <tr><th>序号</th><th>书名</th><th>作者</th><th>定价</th></tr>
    <tr><td>1</td><td>PHP项目实践</td><td>明</td><td>56.00</td></tr><tr><td>2</td><td>Java基础</td><td>强</td><td>88.00</td></tr><tr><td>3</td><td>Python数据分析</td><td>飞</td><td>66.00</td></tr></table>
</body>
</html>

 

posted @ 2022-05-19 10:33  rootoor  阅读(198)  评论(0)    收藏  举报