1-- Copyright (c) 2007, 2013, Oracle and/or its affiliates. 2-- 3-- This program is free software; you can redistribute it and/or modify 4-- it under the terms of the GNU General Public License as published by 5-- the Free Software Foundation; version 2 of the License. 6-- 7-- This program is distributed in the hope that it will be useful, 8-- but WITHOUT ANY WARRANTY; without even the implied warranty of 9-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10-- GNU General Public License for more details. 11-- 12-- You should have received a copy of the GNU General Public License 13-- along with this program; if not, write to the Free Software 14-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA 15 16-- 17-- The initial data for system tables of MySQL Server 18-- 19 20-- When setting up a "cross bootstrap" database (e.g., creating data on a Unix 21-- host which will later be included in a Windows zip file), any lines 22-- containing "@current_hostname" are filtered out by mysql_install_db. 23 24-- Get the hostname, if the hostname has any wildcard character like "_" or "%" 25-- add escape character in front of wildcard character to convert "_" or "%" to 26-- a plain character 27SELECT LOWER( REPLACE((SELECT REPLACE(@@hostname,'_','\_')),'%','\%') )INTO @current_hostname; 28SELECT '{"access":18446744073709551615}' INTO @all_privileges; 29SELECT '{"access":18446744073709551615,"plugin":"mysql_native_password","authentication_string":"invalid","auth_or":[{},{"plugin":"unix_socket"}]}' into @all_with_auth; 30 31 32-- Fill "global_priv" table with default users allowing root access 33-- from local machine if "global_priv" table didn't exist before 34CREATE TEMPORARY TABLE tmp_user_nopasswd LIKE global_priv; 35CREATE TEMPORARY TABLE tmp_user_socket LIKE global_priv; 36-- Classic passwordless root account. 37INSERT INTO tmp_user_nopasswd VALUES ('localhost','root',@all_privileges); 38REPLACE INTO tmp_user_nopasswd SELECT @current_hostname,'root',@all_privileges FROM dual WHERE @current_hostname != 'localhost'; 39REPLACE INTO tmp_user_nopasswd VALUES ('127.0.0.1','root',@all_privileges); 40REPLACE INTO tmp_user_nopasswd VALUES ('::1','root',@all_privileges); 41-- More secure root account using unix socket auth. 42INSERT INTO tmp_user_socket VALUES ('localhost', 'root',@all_with_auth); 43REPLACE INTO tmp_user_socket VALUES ('localhost',IFNULL(@auth_root_socket, 'root'),@all_with_auth); 44IF @auth_root_socket is not null THEN 45 IF not exists(select 1 from information_schema.plugins where plugin_name='unix_socket') THEN 46 INSTALL SONAME 'auth_socket'; END IF; END IF; 47 48INSERT INTO global_priv SELECT * FROM tmp_user_nopasswd WHERE @had_user_table=0 AND @auth_root_socket IS NULL; 49INSERT INTO global_priv SELECT * FROM tmp_user_socket WHERE @had_user_table=0 AND @auth_root_socket IS NOT NULL; 50DROP TABLE tmp_user_nopasswd, tmp_user_socket; 51 52CREATE TEMPORARY TABLE tmp_proxies_priv LIKE proxies_priv; 53INSERT INTO tmp_proxies_priv SELECT @current_hostname, 'root', '', '', TRUE, '', now() FROM DUAL WHERE @current_hostname != 'localhost'; 54INSERT INTO proxies_priv SELECT * FROM tmp_proxies_priv WHERE @had_proxies_priv_table=0; 55DROP TABLE tmp_proxies_priv; 56