Install mysql glibc package in linux and mysqlglibc

Source: Internet
Author: User
Tags mysql host import database mysql command line

Install mysql glibc package in linux and mysqlglibc

Download mysql:

Http://downloads.mysql.com/archives.php

If you select a mysql version, you must be optimistic about it later. Such as: mysql-5.0.90-linux-i686-glibc23.tar.gz

This example is downloaded to the/media directory. This is not a good habit...

 

▲Install mysql:

The following are linux commands

[Plain]View plaincopy
  1. : $ Sudo groupadd mysql
  2. : $ Sudo useradd-g mysql
  3. : $ Cd/usr/local
  4. : $ Tar zvxf/media/mysql-5.0.90-linux-i686-glibc23.tar.gz
[Plain]View plaincopy
  1. : $ Mv mysql-5.0.90-linux-i686-glibc23 mysql
[Plain]View plaincopy
  1. : $ Cd mysql
  2. : $ Sudo chown-R mysql.
  3. : $ Sudo chgrp-R mysql.
  4. : $ Scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql
  5. : & Cd ..
  6. : $ Sudo chown-R root mysql.
  7. : $ Cd mysql
  8. : $ Sudo chown-R mysql data
  9. : $ Bin/mysqld_safe -- basedir =/usr/local/mysql -- user = mysql &

 

So far, mysql is successfully installed.

I don't have ctrl-c in the running status, so I have to open another ssh window...

 

Add a password to the root user of mysql

The following are linux commands

[C-sharp]View plaincopy
  1. Cd/usr/local/mysql/bin./mysql-u root

After entering mysql:

[C-sharp]View plaincopy
  1. Mysql> grant all privileges on *. * TO root @ localhost identified by "chang ";

In fact, the password of the root localhost is set to chang.
The execution is successful, and then exit mysql.

Then, log on to mysql again, and use the password this time:

[C-sharp]View plaincopy
  1. Cd/usr/local/mysql/bin./mysql-u root-p

After entering the password chang, you can log on normally as follows:

Welcome to the MySQL monitor. Commands end with; or/g.
Your MySQL connection id is 1
Server version: 5.0.90 MySQL Community Server (GPL)

Type 'help; 'or'/H' for help. type'/C' to clear the current input statement.

 

View the user information:

[C-sharp]View plaincopy
  1. Mysql> select user, host, password from mysql. user;

The result is as follows:

+ ------ + ----------- + ---------- +
| User | host | password |
+ ------ + ----------- + ---------- +
| Root | localhost | * F05D019BA3BEC01CA9FBD4141E4EA57A28EF3EDF | login (the root password is chang)
| Root | linux | kernel (the root password is blank)
| Root | 127.0.0.1 | empty (the root password is blank)
| Localhost |
+ ------ + ----------- + ---------- +

Change their passwords respectively:

[C-sharp]View plaincopy
  1. Mysql> set password for root @ localhost = password ('Chang ');

[C-sharp]View plaincopy
  1. Mysql> set password for root @ linux = password ('Chang ');

[C-sharp]View plaincopy
  1. Mysql> set password for root@127.0.0.1 = password ('Chang ');

View the user information again and you will find that the user information has been changed.

Then exit mysql.

 

Turn mysql into a service

[C-sharp]View plaincopy
  1. Sudo cp/usr/local/mysql/support-files/mysql. server/etc/init. d/mysql

Start mysql Service

[C-sharp]View plaincopy
  1. Sudo/etc/init. d/mysql start

At this time, you can restart the machine and try again.
After restarting, log on to mysql. you can log on to mysql. Service created!

 

▲Configure mysql

 

[C-sharp]View plaincopy
  1. Vi/etc/my. cnf

(Note: If my. cnf file, so: after the installation of mysql package has a support-files folder, which has a my-huge.cnf, etc., copy my-huge copy, renamed my. cnf, modify it appropriately (based on your database configuration, of course) and copy it to/etc/my. cnf)

After opening my. cnf

Find [client] and add:
Default-character-set = utf8 # default character set: utf8

Find [mysqld] and add:
Default-character-set = utf8 # default character set: utf8
Init_connect = 'set NAMES utf8' # Sets utf8 encoding for connecting to the mysql database to run the mysql database as utf8.

 

After modification, restart.
I restarted the mysql service here:

[C-sharp]View plaincopy
  1. Sudo/etc/init. d/mysql restart

(Sock cannot be found once, so we can restart the service twice !!! Khan .)

 

Then go to mysql and check whether the character set has been changed:

[C-sharp]View plaincopy
  1. Cd/usr/local/mysql/bin./mysql-u root-p

[C-sharp]View plaincopy
  1. Mysql> show variables like 'character % ';

The following figure is displayed:

+ -------------------------- + ---------------------------------------- +
| Variable_name | Value |
+ -------------------------- + ---------------------------------------- +
| Character_set_client | utf8 |
| Character_set_connection | utf8 |
| Character_set_database | utf8 |
| Character_set_filesystem | binary |
| Character_set_results | utf8 |
| Character_set_server | utf8 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/local/mysql/share/mysql/charsets/|
+ -------------------------- + ---------------------------------------- +

Okay. The database language is complete.

 

▲Enable mysql Remote Access
Mysql does not allow remote access by default.
If you log on to mysql with a password, you can log on normally. However, if you use a tool to connect to another machine, an error is returned:
ERROR 1130: Host 192.168.1.6 is not allowed to connect to this MySQL server

 

Method: Change the table method. By default, mysql does not allow remote access and can only be accessed on localhost. At this time, you only need to log on to the computer of localhost. After logging on to mysql, change the "host" item in the "user" table in the "mysql" database to "%" from "localhost"

Mysql-u root-p
Enter password: chang
Mysql> use mysql;
Mysql> update user set host = '%' where user = 'root'; // an error may occur.
Mysql> flush privileges;
Mysql> select host, user from user where user = 'root ';

After executing the preceding command, you can connect to the instance remotely!

Note:

Update user set host = '%' where user = 'root'; // an error may be returned when this command is executed:
ERROR 1062 (23000): Duplicate entry '%-root' for key 1;
Solution:
1. Don't worry about it. Haha.
2. Run the command in this way.
Update user set host = '%' where user = 'root' and host = 'localhost ';
That is, change localhost to all hosts.

 

---------------------------------------------------
Then run the app and report the following error:
ImportError: libmysqlclient_r.so.15: cannot open shared object file: No such file or directory

The solution is to put/usr/local/mysql/lib under
Libmysqlclient_r.so.15
Copy to/usr/lib.

 

So far, mysql installation and configuration are complete!

 

 

======================== I am a gorgeous splitting line ================================ ======

----------------------------------------------------
■ Note:
Note 1: restart and disable the mysql Service
Restart mysql Service
: $ Sudo/etc/init. d/mysql restart
Disable mysql Service
: $ Sudo/etc/init. d/mysql stop
----------------------------------------------------
NOTE 2: Start and Stop mysql in non-service status
Start mysql
Code:
: & Cd/usr/local/mysql
: & Bin/mysqld_safe -- basedir =/usr/local/mysql -- user = mysql &

Stop mysql
Code:
: & Cd/usr/local/mysql
: $ Bin/mysqladmin-uroot-ppassw0rd shutdown

----------------------------------------------------
NOTE 3: What is the mysql command line display in Chinese? No.
Mysql> set names utf8;

---------------------------------------------------
Note 4: mysql database storage path
/Var/lib/mysql

---------------------------------------------------
Note 5: export and import data from mysql
Mysqldump Database Name> file name # Export Database
Mysqladmin create database name # create database
Mysql database name <file name # import database

---------------------------------------------------
Note 6: Modify the root password of mysql
Sudo mysqladmin-u root-p password 'your new password'

Or, the new password is in brackets.
Use mysql;
Update user set Password = password ('Chang') where User = 'root ';
Flush privileges;

---------------------------------------------------
Note 7: What should I do if I forget the mysql root Password?
Sudo/etc/init. d/mysql stop
Sudo mysqld_safe -- skip-grant-tables &
Sudo mysqladmin-u user password 'newpassword
Sudo mysqladmin flush-privileges

---------------------------------------------------
Note 8: Enter the mysql host to log on.
./Mysql-u root-h 127.0.0.1-p


Perform Security Settings

# Bin/mysql_secure_installationNOTE: running all parts of this script is recommended for all MySQL servers in production use! Please read each step carefully! In order to log into MySQL to secure it, we'll need the currentpassword for the root user. if you 've just installed MySQL, andyou haven' t set the root password yet, the password will be blank, so you shoshould just press enter here. enter current password for root (enter for none): <--- Enter the current root password, because we have not set it yet. Press enter OK, successfully used password, moving on... setting the root password ensures that nobody ca N log into the MySQLroot user without the proper authorisation. Set root password? [Y/n] Y <--- whether to set the root password. Of course, enter Y and press enter New password: <--- enter the root password, and press Enter, re-enter new password: <--- enter the root Password again and press enter. During the input process, no password updated successfully is displayed! Reloading privilege tables... Success! By default, a MySQL installation has an anonymous user, allowing anyoneto log into MySQL without having to have a user account created forthem. this is intended only for testing, and to make the installationgo a bit smoother. you shoshould remove them before moving into aproduction environment. remove anonymous users? [Y/n] Y <--- whether to delete anonymous users. Delete the user. Enter Y and press enter... Success! Normally, root shoshould only be allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y <--- whether to delete or disable remote logon by the root user. Of course, disable remote logon by entering Y and press enter... Success! By default, MySQL comes with a database named 'test' that anyone canaccess. this is also intended only for testing, and shocould be removedbefore moving into a production environment. remove test database and access to it? [Y/n] <--- whether to delete the test database, delete it, and press Y to enter-Dropping test database... Success! -Removing privileges on test database ...... Success! Reloading the privilege tables will ensure that all changes made so farwill take effect immediately. Reload privilege tables now? [Y/n] Y <--- refresh permission, enter Y and press enter... Success! Cleaning up... All done! If you 've completed all of the above steps, your MySQLinstallation shoshould now be secure. Thanks for using MySQL!


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.