Linux centos install mysql

Keywords: MySQL Linux mysqladmin mysqldump

Installation steps

#decompression
tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
#Copy the extracted mysql directory
cp -r mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql
#Add user group
groupadd mysql
#Add user mysql to user group mysql
useradd -g mysql mysql

#install
cd /usr/local/mysql/
mkdir ./data/mysql
chown -R mysql:mysql ./
cd /usr/local/mysql/scripts
scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/mysql
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
cp support-files/my-default.cnf /etc/my.cnf

#Modify startup script
vi /etc/init.d/mysqld

#Modification item:
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/mysql

#Startup service
service mysqld start

#Add environment variables and edit / etc/profile, so you can use mysql command anywhere
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile

#mysql start
service mysqld start
#Close mysql
service mysqld stop
#View operation status
service mysqld status

Problem sorting:

  • The server quit without updating PID file (/usr/local/mysql/data/xx.pid)
vi /etc/my.cnf

datadir = /usr/local/mysql/data         #Add to

log-error = /usr/local/mysql/data/error.log  #Add to

#pid-file = /usr/local/mysql/data/mysql.pid   #Annotate

tmpdir = /var/tmp #Not recommended under / tmp

#Save exit
  • Cannot use mysql command bash: mysql: command not found
ln -s /usr/local/mysql/bin/mysql /usr/bin

The reason for this problem is that mysql is missing from the directory / usr/local/bin. You only need to establish a soft link in the following way to solve this problem:
Map mysql installation directory, such as MYSQLPATH/bin/mysql, to / usr/local/bin directory: 
# cd /usr/local/bin
# ln -fs /MYSQLPATH/bin/mysql mysql

There are other common commands, mysqladmin and mysqldump, which can be used when they are not available.
Note: where MYSQLPATH is the actual installation path of mysql
  • Navicat for mysql software connection database error: 2003 can't connect to MySQL service
#Connect mysql
mysql -uroot -p

#Execution statement
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
(username Represents the user name,password The password, replace it with what you want,%Indicates that all computers can be connected or set up ip Address run connection).

#Execute command to make settings effective immediately
flush privileges

Posted by shock on Fri, 20 Mar 2020 11:21:03 -0700