Installation and configuration of MySql8.0 under Centos7
Installation environment: Centos7, mysql8.0
1. Configure yum source
- Download the mysql source installation package
wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
- Install the mysql source
yum localinstall mysql80-community-release-el7-1.noarch.rpm
as shown in the figure. At this time, if you are not logged in as the root user, you need to log in to the root user, enter su and enter the password to enter the root account. After entering root, execute the command to install the mysql source.
Enter y as shown in the figure below
- Check whether the mysql source is installed successfully. After the
yum repolist enabled | grep "mysql.*-community.*"
installation is successful, it will appear as shown in the figure.
Seeing the figure above indicates that the installation is successful.
2. Install mysql
- Install mysql service
yum install mysql-community-server
3. Start mysql
- Start mysql
systemctl start mysqld
- View the startup status of MySQL The status
systemctl status mysqld
after successful startup is as shown in the figure
4. Set startup items
- Set boot up
systemctl enable mysqld
systemctl daemon-reload
5. Modify root local login password
After mysql is installed, a default password will be generated for root in the /var/log/mysqld.log file. Find the
root default password in the following way , and then log in to mysql to modify it:
- View the default password
grep 'temporary password' /var/log/mysqld.log
- Log in to the root account of mysql.
mysql -uroot -p
After Enter password is displayed, enter the default password obtained by viewing.
Note that the entered password will not be displayed, just press Enter after you have entered it.
- Change the default password
set password for 'root'@'localhost'=password('想要修改的密码');
6. Add remote login users
By default, only the root account is allowed to log in locally. If you want to connect to mysql on other machines, you must modify root to allow remote connections, or add
an account that allows remote connections. For security, you can add a new account:
- Create a new login user
GRANT ALL PRIVILEGES ON *.* TO '新创建的用户名' IDENTIFIED BY '设置的密码' WITH GRANT OPTION;
7. Configure the default encoding as utf8
Modify the /etc/my.cnf configuration file and add the encoding configuration under [mysqld], as shown below:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
- Exit mysql
exit
- Enter the etc directory
cd etc
- Modify my.cnf
vi my.cnf
- Enter i to enter the editing mode, after the input, press the esc key, enter: wq to save
- Restart server
systemctl restart mysqld
- View the encoding format of the current database
show variables like '%character%';