New IT forum
11 August 2022, 05:10:08 pm *
Welcome, %1$s. Please login or register.

: CubieBoard 2 and Cubietruck both now in stock.
 
Pages: [1]

Author Topic: How To Install MySQL  (Read 5301 times)

NewIT_Marcus

  • Hero Member
  • *****
  • Posts: 960
How To Install MySQL
« on: 10 October 2009, 01:38:35 pm »

MySQL installation ought to be quite straightforward. Unfortunately it's not. This article contains simple instructions on how to install MySQL and get around a rather unfortunate problem (which seems to be due to a debian packaging error). The bulk of this article is output copied from the terminal, there are around 15 commands here that you will need to type. But when we come to the MySQL statements that need to be entered, Copy & Paste will be your best friend.

To install MySQL server and client:

Installing MySQL without upgrading the out-of-the-box configuration fails, at least it did when we tried it. You should perform a system update as described at the Plug Computer wiki before embarking upon MySQL installation.

When you are ready to install MySQL:

[email protected]:~$ sudo apt-get install mysql-server mysql-client

The following messages (or similar) will scroll up the screen, however no interaction is required except when prompted to enter the MySQL root password during the installation / configuration stage:


Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libx11-data libxcb1 libxau6 libxdmcp6 libx11-6
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient15off
  libnet-daemon-perl libplrpc-perl libterm-readkey-perl mysql-client-5.0
  mysql-common mysql-server-5.0 mysql-server-core-5.0 psmisc
Suggested packages:
  dbishell libipc-sharedcache-perl libcompress-zlib-perl mysql-doc-5.0 tinyca
  mailx
The following NEW packages will be installed
  libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient15off
  libnet-daemon-perl libplrpc-perl libterm-readkey-perl mysql-client
  mysql-client-5.0 mysql-common mysql-server mysql-server-5.0
  mysql-server-core-5.0 psmisc
0 upgraded, 14 newly installed, 0 to remove and 0 not upgraded.
Need to get 37.4MB of archives.
After this operation, 112MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get: 1 http://ports.ubuntu.com jaunty/main mysql-common 5.1.30really5.0.75-0ubuntu10 [62.7kB]
Get: 2 http://ports.ubuntu.com jaunty/main libnet-daemon-perl 0.43-1 [46.9kB]
Get: 3 http://ports.ubuntu.com jaunty/main libplrpc-perl 0.2020-1 [36.0kB]
Get: 4 http://ports.ubuntu.com jaunty/main libdbi-perl 1.607-1 [790kB]
Get: 5 http://ports.ubuntu.com jaunty/main libmysqlclient15off 5.1.30really5.0.75-0ubuntu10 [1769kB]
Get: 6 http://ports.ubuntu.com jaunty/main libdbd-mysql-perl 4.008-1 [133kB]  
Get: 7 http://ports.ubuntu.com jaunty/main mysql-client-5.0 5.1.30really5.0.75-0ubuntu10 [7691kB]
Get: 8 http://ports.ubuntu.com jaunty/main psmisc 22.6-1 [52.4kB]              
Get: 9 http://ports.ubuntu.com jaunty/main mysql-server-core-5.0 5.1.30really5.0.75-0ubuntu10 [3230kB]
Get: 10 http://ports.ubuntu.com jaunty/main mysql-server-5.0 5.1.30really5.0.75-0ubuntu10 [23.4MB]
Get: 11 http://ports.ubuntu.com jaunty/main libterm-readkey-perl 2.30-4 [33.6kB]
Get: 12 http://ports.ubuntu.com jaunty/main libhtml-template-perl 2.9-1 [65.8kB]
Get: 13 http://ports.ubuntu.com jaunty/main mysql-client 5.1.30really5.0.75-0ubuntu10 [54.8kB]
Get: 14 http://ports.ubuntu.com jaunty/main mysql-server 5.1.30really5.0.75-0ubuntu10 [57.0kB]
Fetched 37.4MB in 7min 6s (87.7kB/s)                                          
Preconfiguring packages ...
Selecting previously deselected package mysql-common.
(Reading database ... 28356 files and directories currently installed.)
Unpacking mysql-common (from .../mysql-common_5.1.30really5.0.75-0ubuntu10_all.deb) ...
Selecting previously deselected package libnet-daemon-perl.
Unpacking libnet-daemon-perl (from .../libnet-daemon-perl_0.43-1_all.deb) ...
Selecting previously deselected package libplrpc-perl.
Unpacking libplrpc-perl (from .../libplrpc-perl_0.2020-1_all.deb) ...
Selecting previously deselected package libdbi-perl.
Unpacking libdbi-perl (from .../libdbi-perl_1.607-1_armel.deb) ...
Selecting previously deselected package libmysqlclient15off.
Unpacking libmysqlclient15off (from .../libmysqlclient15off_5.1.30really5.0.75-0ubuntu10_armel.deb) ...
Selecting previously deselected package libdbd-mysql-perl.
Unpacking libdbd-mysql-perl (from .../libdbd-mysql-perl_4.008-1_armel.deb) ...
Selecting previously deselected package mysql-client-5.0.
Unpacking mysql-client-5.0 (from .../mysql-client-5.0_5.1.30really5.0.75-0ubuntu10_armel.deb) ...
Selecting previously deselected package psmisc.
Unpacking psmisc (from .../psmisc_22.6-1_armel.deb) ...
Selecting previously deselected package mysql-server-core-5.0.
Unpacking mysql-server-core-5.0 (from .../mysql-server-core-5.0_5.1.30really5.0.75-0ubuntu10_armel.deb) ...
Setting up mysql-common (5.1.30really5.0.75-0ubuntu10) ...
Selecting previously deselected package mysql-server-5.0.
(Reading database ... 28732 files and directories currently installed.)
Unpacking mysql-server-5.0 (from .../mysql-server-5.0_5.1.30really5.0.75-0ubuntu10_armel.deb) ...
Selecting previously deselected package libterm-readkey-perl.
Unpacking libterm-readkey-perl (from .../libterm-readkey-perl_2.30-4_armel.deb) ...
Selecting previously deselected package libhtml-template-perl.
Unpacking libhtml-template-perl (from .../libhtml-template-perl_2.9-1_all.deb) ...
Selecting previously deselected package mysql-client.
Unpacking mysql-client (from .../mysql-client_5.1.30really5.0.75-0ubuntu10_all.deb) ...
Selecting previously deselected package mysql-server.
Unpacking mysql-server (from .../mysql-server_5.1.30really5.0.75-0ubuntu10_all.deb) ...
Setting up libnet-daemon-perl (0.43-1) ...
Setting up libplrpc-perl (0.2020-1) ...
Setting up libdbi-perl (1.607-1) ...
Setting up libmysqlclient15off (5.1.30really5.0.75-0ubuntu10) ...

Setting up libdbd-mysql-perl (4.008-1) ...
Setting up mysql-client-5.0 (5.1.30really5.0.75-0ubuntu10) ...
Setting up psmisc (22.6-1) ...

Setting up mysql-server-core-5.0 (5.1.30really5.0.75-0ubuntu10) ...
Setting up mysql-server-5.0 (5.1.30really5.0.75-0ubuntu10) ...
 * Stopping MySQL database server mysqld                                 [ OK ]
 * Starting MySQL database server mysqld                                 [ OK ]
 * Checking for corrupt, not cleanly closed and upgrade needing tables.

Setting up libterm-readkey-perl (2.30-4) ...
Setting up libhtml-template-perl (2.9-1) ...
Setting up mysql-client (5.1.30really5.0.75-0ubuntu10) ...
Setting up mysql-server (5.1.30really5.0.75-0ubuntu10) ...
Processing triggers for libc6 ...
ldconfig deferred processing now taking place




If you want to change the location of the files used by MySQL (enabling external storage to be used - an SD card in this example):

First stop the MySQL server: sudo /etc/init.d/mysql stop

Copy the MySQL data files to the SD card: sudo cp -pr /var/lib/mysql /mnt/sd/MySQL-data (or use mv to move, if you are completely certain that you're going to get this bit right). Of course your target directory may be different.

Now make a change to /etc/mysql/my.cnf:

Change:
datadir                = /var/lib/mysql
to:
datadir         = /mnt/sd/MySQL-data

Then restart the MySQL server: sudo /etc/init.d/mysql start



You can test the MySQL configuration by attempting to log in to the MySQL prompt as root and checking the users table:

mysql -u root -p mysql (then you will be prompted for the MySQL root password - you can also try mysql -u root mysql (i.e. without the -p)).

If you are greeted by:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

then you need to read on and learn how to fix this problem. If everything seems OK, you could take a quick peek at the users table and verify that it contains records for user root; at that mysql prompt, type select * from user; and look at the results. (Don't forget that all SQL statements should be terminated with a semi-colon). What you are looking for is 3 records for user root.



Here's an instance of the problem being reported in September 2009: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=545741 . The cause of the error is that no root user was created.

We provide an SQL statement below that should add the required root user, but a special environment needs to be created in order for the statement to be run. The environment needs to ignore all securities that are set in the existing database tables.

* Stop the MySQL server: sudo /etc/init.d/mysql stop
* Start it again in a mode that ignores the permissions: sudo mysqld --skip-grant-tables &
* Get a mysql prompt, so that we can enter the required statements: mysql -u root mysql

You should be greeted by the following, or something similar:


[email protected]:/mnt/sd/downloads$ mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.75-0ubuntu10 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>


At that mysql prompt, type select * from user; and look at the record(s) in the MySQL users file. If there is only one record, for a user named debian-sys-maint, that explains why "root" won't work. The following statement, executed 3 times, with a minor change each time, will bring MySQL to life:

INSERT INTO user (host, user, password, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv, Execute_priv, Repl_slave_priv, Repl_client_priv, Create_view_priv, Show_view_priv, Create_routine_priv, Alter_routine_priv, Create_user_priv) VALUES ('localhost', 'root', PASSWORD('my_secret_password'), 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y');

Repeat the statement (so that it is executed 3 times in all), specifiying secondly the IP address, thirdly the computer name in place of localhost (and change the password too, to your own choice of password).

After executing the three statements, you should try select * from user; again, hopefully now you will see the 3 "root" records (and the unmodified debian-sys-maint record). Still at the mysql prompt:
  • Type FLUSH PRIVILEGES; (this probably isn't necessary, since we will restart the MySQL server momentarily anyway).
  • Type exit;
  • After exiting, type sudo /etc/init.d/mysql stop in order to stop the special instance of the MySQL server.
  • Finally, type sudo /etc/init.d/mysql start in order to start MySQL back in regular mode.

See also:
« Last Edit: 11 October 2009, 09:15:26 pm by NewIT_Marcus »
Logged
Pages: [1]
 
 

Powered by MySQL Powered by PHP SMF 2.0.10 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!