installing MySQL
Let's say you put all the necessary source code or packages in/tmp. If you download the RPM package, it's simpler; If you're downloading a binary package (you don't have an RPM program or you want to customize it), it's a little bit more cumbersome.
RPM Package Installation
You must be a root user to use the RPM installer, the following is the installation process:
$ cd/tmp
$ su
# RPM-UVH mysql* (Install all packages related to MySQL)
This will install all 3 MySQL packages you download. If your system is Redhat Linux, it is recommended to use the RPM installation method, because all the work by the RPM program to help you do a good job.
SOURCE Installation
Compared with the RPM installation, the use of binary source code installation is a little bit of a hassle. However, we can customize the relevant parameters of the installation in the setup script, instead of installing the default installation like the RPM method.
Installing binary source code
If you download the binary source code, its name is similar to: mysql-3.22.21-pc-linux-gnu-i686.tar.gz. You must be the root user and then unzip to the/usr/local directory with the following steps:
$ cd/usr/local
$ su
# tar-zxvf/tmp/mysql-3.22.21-pc-linux-gnu-i686.tar.gz
After all the files have been unpacked, a directory named mysql-3.22.21-pc-linux-gnu-i686 will be created. mysql-3.22.21-pc-linux-gnu-i686 so long):
# ln-s mysql-3.22.21-pc-linux-gnu-i686 MySQL
If you have a new version of MySQL later, you can simply extract the source code to the new path, and then only need to do a symbolic link on it. This is convenient and the data is more secure.
Create a MySQL user
OK, now we're going to build a user account that can run the MySQL daemon, and all MySQL files are owned by this account. Use the linuxconf or Useradd command to add a call to MySQL account, before adding, make sure that no one registered this account, but also temporarily prohibit the login function (but usually in the absence of other people log in the case of debugging machine, so this step can be exempted)
Prepare for MySQL
First let's change the MySQL directory and file ownership to MySQL users and root groups:
# cd/usr/local
# chown-r Mysql:root mysql-3.22.21-pc-linux-gnu-i686 MySQL
Then run a small script program to establish the initialization of the MySQL database. Please complete this task as a MySQL user, which is the only chance we can use this account directly.
# su MySQL
$ CD MySQL
$ scripts/mysql_install_db
$ exit
If you don't have any error messages to show, that's OK.
Running MySQL automatically
In the MySQL binary package, there is a startup script called Myslq.server. Copy it to the/ETC/RC.D/INIT.D directory:
# CD/ETC/RC.D/INIT.D
# cp/usr/local/mysql/support-files/mysql.server MySQL
Then change its properties to "X" (Executable, executable)
# chmod +x MySQL
Finally, run chkconfig to add MySQL to your system's startup service group.
#/sbin/chkconfig--del MySQL
#/sbin/chkconfig--add MySQL
Test MySQL
MySQL has a simple database example test, and its internal database has been maintained on the permissions and account monitoring, so first run MySQL to see if it can work.
Start MySQL First:
#/etc/rc.d/init.d/mysql Start
If everything is OK, you will see the following information appear:
Starting mysqld daemon with databases From/var/lib/mysql
If you install an RPM package, the program is mostly installed in/usr/local/mysql/bin. Run the client program in this directory:
# MySQL
Then you can see that the screen displays the following message:
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 2 to server version:3.22.21
Type ' help ' for help.
Mysql>
Next, use the show databases command to list the installed databases:
mysql> show databases;
Then you can see:
The following are the referenced contents: +----------+ | Database | +----------+ | MySQL | | Test | +----------+ 2 rows in Set (0.00 sec) |
If all is right, that means MySQL can work completely! congratulations! If you want to exit the program, enter: Exit
Mysql> exit;
Bye
Change Administrator Password
The first thing to do after everything is normal is to change the administrator's password. You can run Mysqladmin (note that this command is not necessarily in your path, so it is best to go directly to the directory in this command):
# mysqladmin-u Root Password NewPassword
This command turns the password of the root user into newpassword. Of course you can change the password to something else, because it's easy to crack.