LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
LinkBack Search this Thread
Old 11-24-2012, 01:19 AM   #1
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: san antonio, texas
Distribution: Fedora 64 bit RAID0 + LUKS, CentOS (server), Backtrack, Gentoo Hardened
Posts: 1,439

Rep: Reputation: 80
Configuring mysql server after installation


I've noticed some video demonstrations do not use mysql_install_db before using the client with the server. Isn't this supposed to be a requirement? What's the consequences of not using it? Or are there times it's not needed? I'm only asking these questions because I'm wanting to learn for a certification exam. Thanks.
 
Old 11-24-2012, 07:26 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 2,864

Rep: Reputation: 698Reputation: 698Reputation: 698Reputation: 698Reputation: 698Reputation: 698
mysql_install_db initializes the MySQL data directory and creates the system tables that it contains, if they do not exist; they don't exist in a brand-new installation, so, yes, you have to run it once something like this:
Code:
mysql_install_db --user=mysql [options]
You want mysql (there should be a user mysql in /etc/passwd and a group mysql in /etc/group that look pretty much like this:
Code:
fgrep mysql /etc/passwd /etc/group
/etc/passwd:mysql:x:27:27:MySQL:/var/lib/mysql:/bin/false
/etc/group:mysql:x:27:
Note that user mysql's home directory in this case is /var/lib/mysql; that's the MySQL data directory and is where mysql_install_db will create the system tables on a Slackware system (yours may and probably will vary).

mysql_install_db is a shell program; you can look at it with a text editor. Right up at the top is where the MySQL data directory is defined
Code:
basedir=""
builddir=""
ldata="/var/lib/mysql"
langdir=""
srcdir=""
It's highly recommended that you don't screw with this unless you (1) have a good reason to do so and (2) you know what you're doing.

The "[options]" you can define are listed in section 4 of the MySQL manual (if you want to define a different MySQL data directory, that's how you do it.

Once the MySQL data directory is populated my mysql_install_db (and you've run a couple of tests to make sure), you'll want to run
Code:
mysql_secure_installation
Quote:
This program enables you to improve the security of your MySQL installation in the following ways:

You can set a password for root accounts.

You can remove root accounts that are accessible from outside the local host.

You can remove anonymous-user accounts.

You can remove the test database (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with test_.
Hope this helps some.
 
2 members found this post helpful.
Old 11-27-2012, 01:05 AM   #3
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: san antonio, texas
Distribution: Fedora 64 bit RAID0 + LUKS, CentOS (server), Backtrack, Gentoo Hardened
Posts: 1,439

Original Poster
Rep: Reputation: 80
Thanks for the information. My questions are:
  1. What are the consequences of not running mysql_install_db. For example, a user installed mysql server and began using it, but later realized he forgot to run the command.
  2. Some Linux packages have post installation scripts that may run the command for you. Without knowing whether the Linux package did this or not, does it hurt to run it again? Why or why not?

Last edited by fakie_flip; 11-27-2012 at 01:07 AM.
 
Old 11-27-2012, 06:58 AM   #4
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 2,864

Rep: Reputation: 698Reputation: 698Reputation: 698Reputation: 698Reputation: 698Reputation: 698
Quote:
Originally Posted by fakie_flip View Post
What are the consequences of not running mysql_install_db. For example, a user installed mysql server and began using it, but later realized he forgot to run the command.
Usually that MySQL won't work quite the way it ought to (or not at all). The mysql data base (necessary!) does not exist and you can't set access permissions or do much of anything else.
Quote:
Originally Posted by fakie_flip View Post
Some Linux packages have post installation scripts that may run the command for you. Without knowing whether the Linux package did this or not, does it hurt to run it again? Why or why not?
It won't hurt but, more likely, it won't work either (if I remember my own experience with not having run mysql_install_db some years ago).

Best thing to do is try it -- see if you have a directory mysql in your data directory; e.g., /var/lib/mysql/mysql plus files with names similar to mysql-bin.000001, mysql-bin.index. If you do, you got lucky (maybe). For example, if some post-installation thing ran you should be able to
Code:
mysql --user=mysql mysql
If that opens the mysql data base life is good and you can get on with it. If not, you'll need to do the stuff below.

Make sure that you have a mysql user in /etc/passwd and a mysql group in /etc/group.

Best thing though is to blow away the entire data directory then run mysql_install_db:
Code:
su -
rm -r /var/lib/mysql
mysql_install_db --user=mysql
That will do it -- keep in mind that the data directory is defined at the beginning of mysql_install_db, take a look at that before you blow away something you don't want to (yours may not be /var/lib/mysql).

After you do the above, you probably ought to run mysql_secure_installation (see the manual page).

Hope this helps some.

Last edited by tronayne; 11-27-2012 at 07:08 AM.
 
1 members found this post helpful.
Old 12-07-2012, 02:02 AM   #5
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: san antonio, texas
Distribution: Fedora 64 bit RAID0 + LUKS, CentOS (server), Backtrack, Gentoo Hardened
Posts: 1,439

Original Poster
Rep: Reputation: 80
Should both mysql_install_db and mysql_secure_installation be ran while the server is started or does it not matter?
 
Old 12-07-2012, 03:10 AM   #6
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
I've never heard of 'mysql_secure_installation', so no reply to that; some reading up to do by me

You do not give specifics for the videos. However, installing mysqld in ubuntu (using the package manager) does not require to run 'mysql_install_db'; it will only ask you for a root password to be used in mysql/mysqld during the install and the package manager does the rest.
 
Old 12-07-2012, 05:29 AM   #7
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 546

Rep: Reputation: 58
You should only run one of them: mysql_install_db or mysql_secure_installation.

Like in the previous comment, usually on normal distro's you don't need to run this scripts as they are done by the package or by the init script when ran the first time.
 
Old 12-07-2012, 06:37 AM   #8
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 2,864

Rep: Reputation: 698Reputation: 698Reputation: 698Reputation: 698Reputation: 698Reputation: 698
Quote:
Originally Posted by robertjinx View Post
You should only run one of them: mysql_install_db or mysql_secure_installation.

Like in the previous comment, usually on normal distro's you don't need to run this scripts as they are done by the package or by the init script when ran the first time.
Oh, not quite.

mysql_install_db creates the mysql data base, a test data base and files and directories needed by MySQL. mysql_install_db initializes a new installation (and may be executed by a package installation by some distributions). It's executed by the super user
Code:
su -     or sudo or whatever
mysql_install_db --user=mysql
mysql_secure_installation is executed after mysql_install_db to, as mentioned above:
Quote:
This program enables you to improve the security of your MySQL installation in the following ways:

You can set a password for root accounts.

You can remove root accounts that are accessible from outside the local host.

You can remove anonymous-user accounts.

You can remove the test database (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with test_.
It's executed
Code:
mysql_secure_installation
and you're prompted.

There are manual pages for both and they're detailed in the MySQL manual.

Two separate things, those, and the one must precede the other.

Hope this helps some.
 
Old 12-07-2012, 11:53 AM   #9
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by tronayne View Post
mysql_secure_installation is executed after mysql_install_db to, as mentioned above:

This program enables you to improve the security of your MySQL installation in the following ways:
You can set a password for root accounts.
You can remove root accounts that are accessible from outside the local host.
You can remove anonymous-user accounts.
You can remove the test database (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with test_.
Ah, so that just automates what is described in 2.18.2. Securing the Initial MySQL Accounts in the mysql reference manual (that everybody should read ). I rather do it manually and I think that a beginner should also do that; one can learn from that while one does not learn anything from running a script.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mysql server installation thoufiq Linux - Server 2 04-09-2011 11:47 AM
Mysql-server-5.0 installation failed during configuration Lokathor Debian 20 09-22-2008 01:55 PM
mysql server installation warning: mysql-server-4.1.10a-2.RHEL4.1.i386.rpm: V Buddhike G Linux - Software 3 09-07-2007 06:50 AM
MySQL server installation on Debian redsky Debian 3 09-25-2004 02:06 PM
Configuring MySql server goldfish Linux - Newbie 2 10-15-2003 11:34 AM


All times are GMT -5. The time now is 05:25 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration