码库记事本

码库记事本

centos 7下安装mysql(MariaDB)的教程

小诸哥 0

centos7安装MariaDB教程,分享给大家

1.centos7现状:

  新系统无法再使用yum install mysql-server来安装mysql,因为已使用mariadb代替mysql。

2.安装mariadb:

  1. [[email protected] ~]# yum -y install mariadb*
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4.      * base: mirrors.linode.com
  5.      * extras: mirrors.linode.com
  6.      * updates: mirrors.linode.com
  7. Resolving Dependencies
  8. --> Running transaction check
  9. ---> Package mariadb.x86_64 1:5.5.37-1.el7_0 will be installed
  10. ---> Package mariadb-bench.x86_64 1:5.5.37-1.el7_0 will be installed
  11. ---> Package mariadb-devel.x86_64 1:5.5.37-1.el7_0 will be installed
  12. ---> Package mariadb-embedded.x86_64 1:5.5.37-1.el7_0 will be installed
  13. ---> Package mariadb-embedded-devel.x86_64 1:5.5.37-1.el7_0 will be installed
  14. ---> Package mariadb-libs.x86_64 1:5.5.37-1.el7_0 will be installed
  15. ---> Package mariadb-server.x86_64 1:5.5.37-1.el7_0 will be installed
  16. --> Processing Dependency: perl-DBD-MySQL for package: 1:mariadb-server-5.5.37-1.el7_0.x86_64
  17. ---> Package mariadb-test.x86_64 1:5.5.37-1.el7_0 will be installed
  18. --> Running transaction check
  19. ---> Package perl-DBD-MySQL.x86_64 0:4.023-5.el7 will be installed
  20. --> Finished Dependency Resolution
  21.  
  22. Dependencies Resolved
  23.  
  24. ==========================================================================================================
  25.      Package Arch Version Repository Size
  26. ==========================================================================================================
  27. Installing:
  28.      mariadb x86_64 1:5.5.37-1.el7_0 updates 8.9 M
  29.      mariadb-bench x86_64 1:5.5.37-1.el7_0 updates 385 k
  30.      mariadb-devel x86_64 1:5.5.37-1.el7_0 updates 744 k
  31.      mariadb-embedded x86_64 1:5.5.37-1.el7_0 updates 3.6 M
  32.      mariadb-embedded-devel x86_64 1:5.5.37-1.el7_0 updates 7.4 M
  33.      mariadb-libs x86_64 1:5.5.37-1.el7_0 updates 752 k
  34.      mariadb-server x86_64 1:5.5.37-1.el7_0 updates 11 M
  35.      mariadb-test x86_64 1:5.5.37-1.el7_0 updates 7.9 M
  36. Installing for dependencies:
  37.      perl-DBD-MySQL x86_64 4.023-5.el7 base 140 k
  38.  
  39. Transaction Summary
  40. ==========================================================================================================
  41. Install 8 Packages (+1 Dependent package)
  42.  
  43. Total download size: 40 M
  44. Installed size: 279 M
  45. Downloading packages:
  46. (1/9): mariadb-bench-5.5.37-1.el7_0.x86_64.rpm | 385 kB 00:00:00
  47. (2/9): mariadb-devel-5.5.37-1.el7_0.x86_64.rpm | 744 kB 00:00:00
  48. (3/9): mariadb-embedded-5.5.37-1.el7_0.x86_64.rpm | 3.6 MB 00:00:00
  49. (4/9): mariadb-5.5.37-1.el7_0.x86_64.rpm | 8.9 MB 00:00:00
  50. (5/9): mariadb-libs-5.5.37-1.el7_0.x86_64.rpm | 752 kB 00:00:00
  51. (6/9): mariadb-server-5.5.37-1.el7_0.x86_64.rpm | 11 MB 00:00:00
  52. (7/9): mariadb-embedded-devel-5.5.37-1.el7_0.x86_64.rpm | 7.4 MB 00:00:00
  53. (8/9): mariadb-test-5.5.37-1.el7_0.x86_64.rpm | 7.9 MB 00:00:00
  54. (9/9): perl-DBD-MySQL-4.023-5.el7.x86_64.rpm | 140 kB 00:00:00
  55. ----------------------------------------------------------------------------------------------------------
  56. Total 36 MB/| 40 MB 00:00:01
  57. Running transaction check
  58. Running transaction test
  59. Transaction test succeeded
  60. Running transaction
  61.      Installing : 1:mariadb-libs-5.5.37-1.el7_0.x86_64 1/9
  62.      Installing : 1:mariadb-5.5.37-1.el7_0.x86_64 2/9
  63.      Installing : perl-DBD-MySQL-4.023-5.el7.x86_64 3/9
  64.      Installing : 1:mariadb-server-5.5.37-1.el7_0.x86_64 4/9
  65.      Installing : 1:mariadb-devel-5.5.37-1.el7_0.x86_64 5/9
  66.      Installing : 1:mariadb-embedded-5.5.37-1.el7_0.x86_64 6/9
  67.      Installing : 1:mariadb-embedded-devel-5.5.37-1.el7_0.x86_64 7/9
  68.      Installing : 1:mariadb-test-5.5.37-1.el7_0.x86_64 8/9
  69.      Installing : 1:mariadb-bench-5.5.37-1.el7_0.x86_64 9/9
  70.      Verifying : 1:mariadb-test-5.5.37-1.el7_0.x86_64 1/9
  71.      Verifying : 1:mariadb-embedded-devel-5.5.37-1.el7_0.x86_64 2/9
  72.      Verifying : 1:mariadb-embedded-5.5.37-1.el7_0.x86_64 3/9
  73.      Verifying : 1:mariadb-libs-5.5.37-1.el7_0.x86_64 4/9
  74.      Verifying : 1:mariadb-bench-5.5.37-1.el7_0.x86_64 5/9
  75.      Verifying : 1:mariadb-5.5.37-1.el7_0.x86_64 6/9
  76.      Verifying : 1:mariadb-server-5.5.37-1.el7_0.x86_64 7/9
  77.      Verifying : perl-DBD-MySQL-4.023-5.el7.x86_64 8/9
  78.      Verifying : 1:mariadb-devel-5.5.37-1.el7_0.x86_64 9/9
  79.  
  80. Installed:
  81.      mariadb.x86_64 1:5.5.37-1.el7_0 mariadb-bench.x86_64 1:5.5.37-1.el7_0
  82.      mariadb-devel.x86_64 1:5.5.37-1.el7_0 mariadb-embedded.x86_64 1:5.5.37-1.el7_0
  83.      mariadb-embedded-devel.x86_64 1:5.5.37-1.el7_0 mariadb-libs.x86_64 1:5.5.37-1.el7_0
  84.      mariadb-server.x86_64 1:5.5.37-1.el7_0 mariadb-test.x86_64 1:5.5.37-1.el7_0
  85.  
  86. Dependency Installed:
  87.      perl-DBD-MySQL.x86_64 0:4.023-5.el7
  88.  
  89. Complete!
  90. [[email protected] ~]# systemctl start mariadb.service
  91. [[email protected] ~]# systemctl enable mariadb.service
  92. ln -'/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.servi
  93. ce'
  94. [[email protected] ~]# mysql
  95. Welcome to the MariaDB monitor. Commands end with ; or \g.
  96. Your MariaDB connection id is 2
  97. Server version: 5.5.37-MariaDB MariaDB Server
  98.  
  99. Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
  100.  
  101. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  102.  
  103. MariaDB [(none)]> logout
  104.      -> exit
  105.      ->
  106.      -> ;
  107. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaD
  108. B server version for the right syntax to use near 'logout
  109. exit' at line 1
  110. MariaDB [(none)]> exit
  111. Bye
  112. [[email protected] ~]# systemctl enable mariadb.service
  113. [[email protected] ~]# mysql
  114. Welcome to the MariaDB monitor. Commands end with ; or \g.
  115. Your MariaDB connection id is 3
  116. Server version: 5.5.37-MariaDB MariaDB Server
  117.  
  118. Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
  119.  
  120. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  121.  
  122. MariaDB [(none)]> show databases;
  123. +--------------------+
  124. | Database |
  125. +--------------------+
  126. | information_schema |
  127. | mysql |
  128. | performance_schema |
  129. | test |
  130. +--------------------+
  131. rows in set (0.00 sec)
  132.  
  133. MariaDB [(none)]> use test
  134. Database changed
  135. MariaDB [test]> show tables;
  136. Empty set (0.00 sec)
  137.  
  138. MariaDB [test]> exit
  139. Bye
  140. [[email protected] ~]# mysql_secure_installation
  141. /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
  142.  
  143. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
  144.      SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  145.  
  146. In order to log into MariaDB to secure it, we'll need the current
  147. password for the root user. If you've just installed MariaDB, and
  148. you haven't set the root password yet, the password will be blank,
  149. so you should just press enter here.
  150.  
  151. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
  152. Enter current password for root (enter for none):
  153. OK, successfully used password, moving on...
  154.  
  155. Setting the root password ensures that nobody can log into the MariaDB
  156. root user without the proper authorisation.
  157.  
  158. Set root password? [Y/n] y
  159. New password:
  160. Re-enter new password:
  161. Password updated successfully!
  162. Reloading privilege tables..
  163.      ... Success!
  164.  
  165.  
  166. By default, a MariaDB installation has an anonymous user, allowing anyone
  167. to log into MariaDB without having to have a user account created for
  168. them. This is intended only for testing, and to make the installation
  169. go a bit smoother. You should remove them before moving into a
  170. production environment.
  171.  
  172. Remove anonymous users? [Y/n] y
  173.      ... Success!
  174.  
  175. Normally, root should only be allowed to connect from 'localhost'. This
  176. ensures that someone cannot guess at the root password from the network.
  177.  
  178. Disallow root login remotely? [Y/n] y
  179.      ... Success!
  180.  
  181. By default, MariaDB comes with a database named 'test' that anyone can
  182. access. This is also intended only for testing, and should be removed
  183. before moving into a production environment.
  184.  
  185. Remove test database and access to it? [Y/n] y
  186.      - Dropping test database...
  187.      ... Success!
  188.      - Removing privileges on test database...
  189.      ... Success!
  190.  
  191. Reloading the privilege tables will ensure that all changes made so far
  192. will take effect immediately.
  193.  
  194. Reload privilege tables now? [Y/n] y
  195.      ... Success!
  196.  
  197. Cleaning up...
  198.  
  199. All done! If you've completed all of the above steps, your MariaDB
  200. installation should now be secure.
  201.  
  202. Thanks for using MariaDB!
  203. [[email protected] ~]# mysql -uroot -p
  204. Enter password:
  205. Welcome to the MariaDB monitor. Commands end with ; or \g.
  206. Your MariaDB connection id is 15
  207. Server version: 5.5.37-MariaDB MariaDB Server
  208.  
  209. Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
  210.  
  211. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  212.  
  213. MariaDB [(none)]> show databases;
  214. +--------------------+
  215. | Database |
  216. +--------------------+
  217. | information_schema |
  218. | mysql |
  219. | performance_schema |
  220. | zbphp.com |
  221. +--------------------+
  222. rows in set (0.00 sec)
  223.  
  224. MariaDB [(none)]>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

标签: