Accidentally import the MySQL user table into TiDB, or forget the password - distributed-database

If I accidentally import the MySQL user table into TiDB, or forget the password and cannot log in, how to deal with it?

Restart the TiDB service, add the -skip-grant-table=true parameter in the configuration file. Log into the cluster without password and recreate the user, or recreate the mysql.user table using the following statement:
DROP TABLE IF EXIST mysql.user;
CREATE TABLE if not exists mysql.user (
Host CHAR(64),
User CHAR(16),
Password CHAR(41),
Select_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Insert_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Update_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Delete_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Drop_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Process_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Grant_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
References_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Alter_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Show_db_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Super_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_tmp_table_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Lock_tables_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Execute_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_view_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Show_view_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_routine_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Alter_routine_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Index_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_user_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Event_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Trigger_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
PRIMARY KEY (Host, User));
INSERT INTO mysql.user VALUES ("%", "root", "", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y");

Related

How to open an image?

enter image description here
I use 'openImage' package to import multiple images,
#this sets the directory
list\<- list.files("C://Users//Bilal//Desktop//test//bb", all.files
= FALSE,full.names = TRUE)
#this loop to import the images
df<-data.frame()
#df <-list()
for (i in seq_along(lista)) {
pic<-readImage(lista[i])
pic<-rgb_2gray(pic)
pic<-resizeImage(pic, width = 48, height = 64)
pic<-as.vector(pic)
pre_pic<-t(pic)
df<-rbind(df,pre_pic)}
#this code is used to open the image but the second line does not work
#Error in image.default(df, xaxt = "n", yaxt = "n", col = grayscale) :
#'z' must be a matrix
grayscale <- gray(seq(0, 1, length = 100))
image(df[,,1], xaxt='n', yaxt='n', col=grayscale)
This is what I expect to see
I understand now what's happening; thanks for sharing the image. First- you were/are using grDevices::image() <- the base R function.
The error tells you that R can't determine how you shaped your data. When you flattened the matrix into a vector, you knew it was 48 x 64, but that information wasn't there when you sent it to image.
You could do either one of the following:
# before making it a vector
image(t(p3), col = grayscale, yaxt = 'n', xaxt = 'n')
# after making it a row in a data frame
image(t(matrix(unlist(df[1,]), ncol = 64, nrow = 48)),
col = grayscale, yaxt = 'n', xaxt = 'n')

Bug in a custom encryption/decryption program

I'm creating an encryption software in python 3.5. It should go along a key, using key[0] to shift raw[0], then key[1] to shift raw[1] etc, going back to key[0] when raw[i] is greater then key[i%len(key)].
# Converts the key into a numerical list.
def convert(alph, key):
for i in range(0, len(key)):
rem = alph.index(key[i])
numkey.append(rem)
print(numkey)
return numkey
#shifts the text dependant on the key
def encrypt (numkey, raw, alph):
encr = ""
emi = ()
emi = list(emi)
for i in range (0, len(raw)):
rem = raw[i]
rem = alph.index(rem)
suba = i%len(numkey)
ram = numkey[suba]
shift = (rem + ram) % 28 #ensures that shift is an index of alph
shift = alph[shift]
emi.append(shift)
for i in range(0, len(emi)):
encr = encr + str(emi[i])
print (encr)
letters = [
' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 't', 's', 'u', 'v', 'w',
'x', 'y', 'z', '.', ',', '!', '?']
raw_key = input("Please enter the key:\n")
raw_text = input("Please enter the text you would like to encrypt (no numbers or capitals):")
numkey = convert(letters, raw_key)
encrypt(numkey, raw_text, letters)
My problem is with the decryption program(below).
# Converts the key into a numerical list.
def convert(alph, key):
numkey = ()
numkey = list(numkey) # parse numkey as list
for i in range(0, len(key)):
rem = alph.index(key[i])
numkey.append(rem)
return numkey
# shifts the text dependant on the key
def encrypt (numkey,raw,alph):
encr = ""
emi = ()
emi = list(emi)
for i in range (0, len(raw)):
rem = raw[i]
rem = alph.index(rem)
suba = i%len(numkey)
ram = numkey[suba]
shift = (rem - ram)
if shift < 0:
shift = shift + 28
else:
pass
shift = alph[shift]
emi.append(shift)
for i in range(0, len(emi)):
encr = encr + str(emi[i])
print (encr)
letters = [
' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 't', 's', 'u', 'v', 'w',
'x', 'y', 'z', '.', ',' ,'!' ,'?']
raw_key = input("Please enter the key:\n")
raw_text = input("Please enter the text you would like to decrypt:\n")
numkey = convert(letters, raw_key)
encrypt(numkey, raw_text, letters)
For some reason, after encrypting the characters ",", "?" & "!", if I pass them beck through the decryption they always returns as " ", "a" and "b" respectively. This isn't a problem with any other element in the characters list.
If anyone can spot the problem I would be extremely grateful.
The problem is here in the encryption program:
shift = (rem + ram) % 28
The length of letters is 31 not 28. This is where you're looping back to the beginning of the array prematurely.
The problem is mirrored here in the decryption program:
shift = shift + 28
There are other problems as well. Just a few examples:
In the encryption program numkey is not initialized in convert()
no need to use range(), just use for char in key:
no need for the lst = () followed by lst = list(lst) pattern, just use a list in the first place, lst = []
no checking for invalid characters
function is still named encrypt() in the decryption program
Here's a quick first pass at cleaning both up.
Encryption:
import sys
LETTERS = (
' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 't', 's', 'u', 'v', 'w',
'x', 'y', 'z', '.', ',', '!', '?')
# Converts the key into a numerical list.
def convert(alph, key):
numkey = []
for char in key:
if char not in alph:
sys.exit("Invalid character")
numkey.append(alph.index(char))
print(numkey)
return numkey
# Shifts the text dependant on the key.
def encrypt (numkey, raw, alph):
encr = ""
for i, char in enumerate(raw):
if char not in alph:
sys.exit("Invalid character")
rem = alph.index(char)
ram = numkey[i % len(numkey)]
# Ensure that shift is an index of alph
shift = (rem + ram) % len(alph)
encr = encr + alph[shift]
print(encr)
raw_key = input("Please enter the key: ")
raw_text = input("Please enter the text you would like to encrypt (no numbers or capitals):\n")
numkey = convert(LETTERS, raw_key)
encrypt(numkey, raw_text, LETTERS)
Decryption:
import sys
LETTERS = (
' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 't', 's', 'u', 'v', 'w',
'x', 'y', 'z', '.', ',' ,'!' ,'?')
# Converts the key into a numerical list.
def convert(alph, key):
numkey = []
for char in key:
if char not in alph:
sys.exit("Invalid character")
numkey.append(alph.index(char))
return numkey
# Shifts the text dependant on the key.
def decrypt(numkey, raw, alph):
decr = ""
for i, char in enumerate(raw):
if char not in alph:
sys.exit("Invalid character")
rem = alph.index(char)
ram = numkey[i % len(numkey)]
shift = rem - ram
if shift < 0:
shift = shift + len(alph)
decr = decr + alph[shift]
print(decr)
raw_key = input("Please enter the key: ")
raw_text = input("Please enter the text you would like to decrypt:\n")
numkey = convert(LETTERS, raw_key)
decrypt(numkey, raw_text, LETTERS)

r function list all parameters including ellipses

Is there any ways to list all parameters including ellipses(additional parameters with three dots) of R function? For example,I want to know "qplot" function's parameters,the only way I found is args(qplot),which result
> args(qplot)
function (x, y = NULL, ..., data, facets = NULL, margins = FALSE,
geom = "auto", xlim = c(NA, NA), ylim = c(NA, NA), log = "",
main = NULL, xlab = deparse(substitute(x)), ylab = deparse(substitute(y)),
asp = NA, stat = NULL, position = NULL)
But I really want to know what additional parameters the three dots represents can pass into this function.for example,the "shape" parameter.
The three dot ellipsis ... refer to any number of function arguments that get processes/passed on within the function body.
For example, in the case of qplot, the function body (which you can see if you execute qplot) reveals that any additional function arguments will be used as additional aesthetic specifications.
The relevant lines are:
arguments <- as.list(match.call()[-1])
env <- parent.frame()
aesthetics <- compact(arguments[.all_aesthetics])
where
.all_aesthetics <- c("adj", "alpha", "angle", "bg", "cex", "col", "color",
"colour", "fg", "fill", "group", "hjust", "label", "linetype", "lower",
"lty", "lwd", "max", "middle", "min", "pch", "radius", "sample", "shape",
"size", "srt", "upper", "vjust", "weight", "width", "x", "xend", "xmax",
"xmin", "xintercept", "y", "yend", "ymax", "ymin", "yintercept", "z")
The definition of .all_aesthetics can be found here.

PrevR - could not find function "as.prevR"

I am trying to use PrevR (https://cran.r-project.org/web/packages/prevR/prevR.pdf), and I am at the very beginning.
When I run this code:
install.packages('prevR')
par(ask = TRUE)
col <- c(id = "cluster",
x = "x",
y = "y",
n = "n",
pos = "pos",
c.type = "residence",
wn = "weighted.n",
wpos = "weighted.pos"
)
dhs <- as.prevR(fdhs.clusters,col, fdhs.boundary)
I get this error message:
Error in as.prevR(fdhs.clusters, col, fdhs.boundary) :
could not find function "as.prevR"
I thought the function as.prevR was included in the prevR package I installed. Am I missing something?
Thank you

How to change maker in scatter plot in Julia

I would like to change the marker style of a 2D scatter plot based on the value in a vector, ultimately displaying 3 dimensions on two axes. Below is what I'd like to do and the error I get when I try it.
x = rand(1:30,100)
y = rand(20:30,100)
MyMarker = [fill("o",50);fill("x",50)]
scatter(x,y,marker=MyMarker,alpha=0.5)
LoadError: PyError (:PyObject_Call) <type 'exceptions.ValueError'>
ValueError(u"Unrecognized marker style ['o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x']",)
File "/home/lara/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/pyplot.py", line 3251, in scatter
edgecolors=edgecolors, data=data, **kwargs)
File "/home/lara/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/__init__.py", line 1812, in inner
return func(ax, *args, **kwargs)
File "/home/lara/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/axes/_axes.py", line 3877, in scatter
marker_obj = mmarkers.MarkerStyle(marker)
File "/home/lara/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/markers.py", line 171, in __init__
self.set_marker(marker)
File "/home/lara/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/markers.py", line 252, in set_marker
' {0}'.format(marker))
while loading In[91], in expression starting on line 1
in getindex at /home/lara/.julia/v0.4/PyCall/src/PyCall.jl:228
in pysequence_query at /home/lara/.julia/v0.4/PyCall/src/conversions.jl:717
[inlined code] from /home/lara/.julia/v0.4/PyCall/src/conversions.jl:733
in pytype_query at /home/lara/.julia/v0.4/PyCall/src/conversions.jl:762
in convert at /home/lara/.julia/v0.4/PyCall/src/conversions.jl:782
in pycall at /home/lara/.julia/v0.4/PyCall/src/PyCall.jl:363
in call at /home/lara/.julia/v0.4/PyCall/src/PyCall.jl:372
in close_queued_figs at /home/lara/.julia/v0.4/PyPlot/src/PyPlot.jl:401
I have tried the following, neither of which is exactly what I want to do but they are close enough, and neither works.
using Plots
pyplot(size=(400,200), legend=false) # set backend and set some session defaults
scatter(rand(30),m = ColorGradient([:red,:green,:blue]),zcolor = repmat([0,0.5,1],10))
using Plots
pyplot(size=(400,200), legend=false) # set backend and set some session defaults
scatter(rand(30),
m = ColorGradient([:red,:green,:blue]), # colors are defined by a gradient
zcolor = repmat([0,0.5,1],10) # sample from the gradient, cycling through: 0, 0.5, 1
)
Can anyone tell me how to make marker take in a vector?
Update
I have a work around but I don't like having to do this: dividing the data into separate sets and then plotting them on the same axes:
PyPlot.plot(spacerdataActualSpacer[:Length],spacerdataActualSpacer[:Curvature],marker="x",".")
PyPlot.plot(spacerdataNoActualSpacer[:Length],spacerdataNoActualSpacer[:Curvature],marker="o",".")
There's a few different things you can try (I'm on Plots dev, so I can't be certain what will work for you out of the box):
scatter(rand(30), group = repmat(1:3,10), marker=:auto)
scatter(rand(30), group = repmat(1:3,10), shape=[:+ :o :utri])
scatter(rand(30), group = repmat(1:3,10), shape=[:+ :o :utri], layout=(3,1))
Let me know if any of that is what you want. To be honest I'm not totally sure I know what your ideal viz will look like.

Resources