1. 程式人生 > 其它 >docker內centos安裝mysql匯入sql

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) MariaDB [bookstore]>