Mysql安装

Mysql安装本来很简单,但由于升级老版本或者机器中本来安装过mysql等原因导致出现各类问题,如找不到sock文件等。最好的解决方法是:通过find找到所有mysql目录与文件,彻底删除这些文件,然后按照下面的或官网的安装方法安装(我个人也因为安装了存储引擎还是MYISAM的5.1版本,导致各种安装不了5.7的问题)。

Yum install

 
1. Adding the MySQL Yum Repository
Besides using yum-config-manager or the dnf config-manager command, you can also select a release series by editing manually the /etc/yum.repos.d/mysql-community.repo file. This is a typical entry for a release series' subrepository in the file:
Find the entry for the subrepository you want to configure, and edit the enabled option. Specifyenabled=0 to disable a subrepository, or enabled=1 to enable a subrepository. For example, to install MySQL 5.6, make sure you have enabled=0 for the above subrepository entry for MySQL 5.7, and have enabled=1 for the entry for the 5.6 series:
You should only enable subrepository for one release series at any time. When subrepositories for more than one release series are enabled, the latest series will be used by Yum.
Verify that the correct subrepositories have been enabled and disabled by running the following command and checking its output (for dnf-enabled systems, replace yum in the command with dnf):
yum repolist enabled | grep mysql2. Installing MySQL
Install MySQL by the following command (for dnf-enabled systems, replace yum in the command withdnf):
sudo yum install mysql-community-serverThis installs the package for MySQL server (mysql-community-server) and also packages for the components required to run the server, including packages for the client (mysql-community-client), the common error messages and character sets for client and server (mysql-community-common), and the shared client libraries (mysql-community-libs).
  1. Starting the MySQL Server
Start the MySQL server with the following command:
sudo service mysqld startYou can check the status of the MySQL server with the following command:
sudo service mysqld statusAt the initial start up of the server, the following happens, given that the data directory of the server is empty:
  • The server is initialized.
  • SSL certificate and key files are generated in the data directory.
  • The validate_password plugin is installed and enabled.
  • A superuser account 'root'@'localhost is created. A password for the superuser is set and stored in the error log file. To reveal it, use the following command:
sudo grep 'temporary password' /var/log/mysqld.logChange the root password as soon as possible by logging in with the generated, temporary password and set a custom password for the superuser account:
mysql -uroot -p ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
 

Package install

 
tar -xvf mysql-5.7.12-linux-glibc2.5-x86_64.tar
 
rm -rf mysql-test-5.7.12-linux-glibc2.5-x86_64.tar.gz
 
tar -xvf mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
 
cp mysql-5.7.12-linux-glibc2.5-x86_64 /usr/local/mysql -r
 
cd /usr/local/mysql
 
groupadd mysql
 
useradd -r -g mysql mysql
 
chown -R mysql:mysql ./
 
chown -R mysql:mysql ./
 
bin/mysqld --initialize
 
bin/mysql_ssl_rsa_setup
 
bin/mysqld
 
cp support-files/my-default.cnf /etc/my.cnf
 
cp support-files/mysql.server /etc/init.d/mysql
 
ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
 
 
 
mysql:
 
SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');
 
create user 'test'@'localhost' identified by '123456';
 
grant all privileges on mdbook.* to mdbook@'%' identified by 'mdbook_123456';
 
SHOW GRANTS FOR mdbook@'%';
 
 
posted @ 2017-03-16 11:09  MILAS  Views(99)  Comments(0)    收藏  举报