MySql installation and uninstallation under Linux

mysql installation under Linux

1. Go to the /usr/local directory

tar -zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz

cp mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql -r

Or the following method, create a symbolic link mysql for it, which is convenient for input. The following method is not recommended.

ln -s mysql-5.6.35-linux-glibc2.5-x86_64 mysql

 

2. Add the system mysql group and mysql user:

groupadd mysql

useradd -r -g mysql mysql

 

3. Install the database

Enter the directory where the mysql software is installed:

cd /usr/local/mysql

Modify the current directory owner to the mysql user:

chown -R mysql:mysql ./

Install the database: execute the command 

./scripts/mysql_install_db --user=mysql

Change the current directory owner to root user:

 chown -R root:root ./

Modify the current data directory owner to the mysql user:

chown -R mysql:mysql data

 

4. Start the mysql service

Add boot start:

cp support-files/mysql.server /etc/init.d/mysql Put the startup script in the boot initialization directory

Start the mysql service:

service mysql start

See that the mysql service indicates that the startup was successful

ps -ef | grep mysql

 

5. Modify the root user password of mysql, the initial root password is empty:

./bin/mysqladmin -u root password 'suntech#2016'

error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'

Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!

cd / var / lib / mysql /

Since mysql's default mysql.sock is in /var/lib/mysql/mysql.sock, create a symbolic link:

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

re-execute

./bin/mysqladmin -u root password 'suntech#2016'

 

6. Put the mysql client to the default path:

ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql

 

7. Connect to the database

mysql -u root -p

 

8. Authorization

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'suntech#2016' WITH GRANT OPTION;

FLUSH PRIVILEGES;

 

9. Stop mysql and check the status command

service mysql stop

service mysql status

 

MySql uninstall

1. Find the MySQL installation directory and delete it completely

find / -name mysql

 

/usr/lib64/mysql

/usr/share/mysql

/usr/local/mysql

/usr/local/mysql-5.6.35-linux-glibc2.5-x86_64/include/mysql

/usr/local/mysql-5.6.35-linux-glibc2.5-x86_64/bin/mysql

/usr/local/bin/mysql

/etc/rc.d/init.d/mysql

/ var / lib / mysql

/var/lib/mysql/mysql

/var/lock/subsys/mysql

 

2. Delete some configuration files

The configuration file generally has /etc/my.cnf or /etc/init.d/mysql.server,

rm -rf /etc/my.cnf

 

4: Delete MySQL users and user groups

id mysql

userdel mysql

 

Installation under windows

1. Start the cmd command line as an administrator, switch the directory to the bin directory under the mysql directory, and execute the command mysqld install to install mysql.
2. Then execute the command mysqld --initialize-insecure --user=mysql to create a new user whose username is root and whose password is empty.
//This step is missing in the original article, so the next step cannot be executed successfully.
3. Execute the command net start mysql to start the mysql service.
4.mysql -uroot -p
 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
 Find my.ini
 and add skip-grant-tables under mysqld, save and exit
and restart mySQL after saving
5. Then run cmd and
enter mysql -u root -p to log in without a password. When password: appears, press Enter to enter.
mysql> use mysql;
mysql> update user set password=password("root") where user="root";
mysql> flush privileges;
mysql> quit;

 

mysql authorization

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;  

FLUSH   PRIVILEGES; 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326444556&siteId=291194637